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

View file

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