update session_auth_axum

This commit is contained in:
Greg Johnston 2024-01-10 14:05:24 -05:00
parent 7f532cda70
commit 2af0d3d781
3 changed files with 10 additions and 13 deletions

Binary file not shown.

View File

@ -162,9 +162,7 @@ pub async fn login(
let user: User = User::get_from_username(username, &pool)
.await
.ok_or_else(|| {
ServerFnError::ServerError("User does not exist.".into())
})?;
.ok_or_else(|| ServerFnError::new("User does not exist."))?;
match verify(password, &user.password)? {
true => {
@ -207,9 +205,7 @@ pub async fn signup(
User::get_from_username(username, &pool)
.await
.ok_or_else(|| {
ServerFnError::ServerError(
"Signup failed: User does not exist.".into(),
)
ServerFnError::new("Signup failed: User does not exist.")
})?;
auth.login_user(user.id);

View File

@ -6,8 +6,8 @@ if #[cfg(feature = "ssr")] {
use axum::{
response::{Response, IntoResponse},
routing::get,
extract::{Path, State, RawQuery},
http::{Request, header::HeaderMap},
extract::{Path, State},
http::{Request},
body::Body as AxumBody,
Router,
};
@ -21,12 +21,12 @@ if #[cfg(feature = "ssr")] {
use axum_session::{SessionConfig, SessionLayer, SessionStore};
use axum_session_auth::{AuthSessionLayer, AuthConfig, SessionSqlitePool};
async fn server_fn_handler(State(app_state): State<AppState>, auth_session: AuthSession, path: Path<String>, headers: HeaderMap, raw_query: RawQuery,
async fn server_fn_handler(State(app_state): State<AppState>, auth_session: AuthSession, path: Path<String>,
request: Request<AxumBody>) -> impl IntoResponse {
log!("{:?}", path);
handle_server_fns_with_context(path, headers, raw_query, move || {
handle_server_fns_with_context( move || {
provide_context(auth_session.clone());
provide_context(app_state.pool.clone());
}, request).await
@ -58,10 +58,11 @@ if #[cfg(feature = "ssr")] {
let auth_config = AuthConfig::<i64>::default();
let session_store = SessionStore::<SessionSqlitePool>::new(Some(pool.clone().into()), session_config).await.unwrap();
sqlx::migrate!()
if let Err(e) = sqlx::migrate!()
.run(&pool)
.await
.expect("could not run SQLx migrations");
.await {
eprintln!("{e:?}");
}
// Explicit server function registration is no longer required
// on the main branch. On 0.3.0 and earlier, uncomment the lines