From 2af0d3d781220b27776c76d5eff884570d7f209f Mon Sep 17 00:00:00 2001 From: Greg Johnston Date: Wed, 10 Jan 2024 14:05:24 -0500 Subject: [PATCH] update session_auth_axum --- examples/session_auth_axum/Todos.db | Bin 40960 -> 40960 bytes examples/session_auth_axum/src/auth.rs | 8 ++------ examples/session_auth_axum/src/main.rs | 15 ++++++++------- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/examples/session_auth_axum/Todos.db b/examples/session_auth_axum/Todos.db index df5f7158d3af3828e608dc893e65260e667a775a..3f65a9407056ed189c8690a9d576eab6ca005526 100644 GIT binary patch delta 492 zcmZoTz|?SnX@WGP=tLQ3R#67Mq6HgM7VvX0@dq*R&*2Z+EGVGEpOVDH63SAUoM@b8 zW{_;Gn`~-op=)AjVxeo{0g`b|H8e}Jv@|o&HB2!#*ELB=HqlKqFfh@zNJ=p?H%l~6 zwJiRiCqFN}B(*44$to=|r#Q8C@*MdLptb86_;2v9-z=!G zm|s(aIh2tYqnS3}(AQA_YW8B_U&8MNbh90QR0IE;G5`Po diff --git a/examples/session_auth_axum/src/auth.rs b/examples/session_auth_axum/src/auth.rs index 6dc78c269..0a9c8caac 100644 --- a/examples/session_auth_axum/src/auth.rs +++ b/examples/session_auth_axum/src/auth.rs @@ -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); diff --git a/examples/session_auth_axum/src/main.rs b/examples/session_auth_axum/src/main.rs index a321729fd..9797d70d0 100644 --- a/examples/session_auth_axum/src/main.rs +++ b/examples/session_auth_axum/src/main.rs @@ -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, auth_session: AuthSession, path: Path, headers: HeaderMap, raw_query: RawQuery, + async fn server_fn_handler(State(app_state): State, auth_session: AuthSession, path: Path, request: Request) -> 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::::default(); let session_store = SessionStore::::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