Skip to content

Commit

Permalink
Feat: use app state signed cookie jar on login handler
Browse files Browse the repository at this point in the history
  • Loading branch information
rhwddy committed May 2, 2024
1 parent e44fe36 commit 52187c9
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/handlers/user.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
models::user::{CheckUserLogin, CreateUser, LoginUser, User},
structs::app_state::AppState,
utils::{session, use_signed_cookies::set_signed_cookie},
utils::session,
};
use axum::{
extract::{Path, State},
Expand All @@ -10,6 +10,7 @@ use axum::{
Json,
};

use axum_extra::extract::cookie::Cookie;
use serde_json::json;
use std::sync::Arc;

Expand Down Expand Up @@ -55,10 +56,10 @@ pub async fn authenticate(
let is_valid = bcrypt::verify(body.password, &user.password_hash).unwrap();
if is_valid {
let session_id = session::create(user.id).await;
let cookies = set_signed_cookie("session_id".to_string(), session_id.to_string());

return Ok((
StatusCode::OK,
cookies,
app_state.signed_jar.clone().add(Cookie::new("session_id", session_id.to_string())),
Json(json!({"status": "success", "message": "User is authorized"})),
));
} else {
Expand Down

0 comments on commit 52187c9

Please sign in to comment.