Skip to content

Commit

Permalink
fix: max-age for cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
ElaBosak233 committed Nov 11, 2024
1 parent 68f41bd commit 443ac93
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/config/auth/jwt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Config {
pub secret_key: String,
pub expiration: u64,
pub expiration: i64,
}
2 changes: 1 addition & 1 deletion src/util/jwt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub async fn generate_jwt_token(user_id: i64) -> String {
let claims = Claims {
id: user_id,
exp: (chrono::Utc::now()
+ chrono::Duration::minutes(crate::config::get_config().auth.jwt.expiration as i64))
+ chrono::Duration::minutes(config::get_config().auth.jwt.expiration))
.timestamp() as usize,
};

Expand Down
12 changes: 9 additions & 3 deletions src/web/router/user/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use serde::{Deserialize, Serialize};
use validator::Validate;

use crate::{
config,
database::get_db,
model::user::group::Group,
util::{jwt, validate},
Expand Down Expand Up @@ -260,9 +261,14 @@ pub async fn login(Json(mut body): Json<LoginRequest>) -> Result<impl IntoRespon
let mut headers = HeaderMap::new();
headers.insert(
SET_COOKIE,
format!("token={}; Path=/; HttpOnly; SameSite=Strict", token)
.parse()
.unwrap(),
format!(
"token={}; Max-Age={}; Path=/; HttpOnly; SameSite=Strict",
token,
chrono::Duration::minutes(config::get_config().auth.jwt.expiration)
.num_seconds()
)
.parse()
.unwrap(),
);

Ok((
Expand Down

0 comments on commit 443ac93

Please sign in to comment.