feat: fix incorrect JWT cookie key

This commit is contained in:
GW_MC
2025-12-20 16:40:41 +08:00
parent 3f252a8abd
commit be63fcbc37
2 changed files with 8 additions and 2 deletions

View File

@@ -7,6 +7,7 @@ use axum::{
response::Response,
};
use axum_extra::extract::cookie::CookieJar;
use tracing::debug;
use uuid::Uuid;
use crate::{
@@ -25,6 +26,7 @@ pub async fn require_auth(
let token = if let Some(cookie) = cookies.get(JWT_COOKIE_NAME) {
cookie.value().to_string()
} else {
debug!("No JWT cookie found. cookies: {:?}", cookies);
return handle_unauthenticated().await;
};

View File

@@ -11,7 +11,10 @@ use serde::{Deserialize, Serialize};
use serde_json::{Value, from_value};
use tracing::{error, warn};
use crate::routes::{AppState, api::openapi::tag::AUTH_TAG};
use crate::{
helpers::constants::JWT_COOKIE_NAME,
routes::{AppState, api::openapi::tag::AUTH_TAG},
};
/// Login request payload
#[derive(Serialize, Deserialize, utoipa::ToSchema)]
@@ -81,7 +84,8 @@ pub async fn login(State(state): State<Arc<AppState>>, Json(payload): Json<Value
.header(
SET_COOKIE,
format!(
"token={}; HttpOnly; Path=/; Max-Age={}; SameSite=Strict;",
"{}={}; HttpOnly; Path=/; Max-Age={}; SameSite=Strict;",
JWT_COOKIE_NAME,
jwt,
claims.exp - claims.iat
),