feat: fix incorrect JWT cookie key
This commit is contained in:
@@ -7,6 +7,7 @@ use axum::{
|
|||||||
response::Response,
|
response::Response,
|
||||||
};
|
};
|
||||||
use axum_extra::extract::cookie::CookieJar;
|
use axum_extra::extract::cookie::CookieJar;
|
||||||
|
use tracing::debug;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -25,6 +26,7 @@ pub async fn require_auth(
|
|||||||
let token = if let Some(cookie) = cookies.get(JWT_COOKIE_NAME) {
|
let token = if let Some(cookie) = cookies.get(JWT_COOKIE_NAME) {
|
||||||
cookie.value().to_string()
|
cookie.value().to_string()
|
||||||
} else {
|
} else {
|
||||||
|
debug!("No JWT cookie found. cookies: {:?}", cookies);
|
||||||
return handle_unauthenticated().await;
|
return handle_unauthenticated().await;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,10 @@ use serde::{Deserialize, Serialize};
|
|||||||
use serde_json::{Value, from_value};
|
use serde_json::{Value, from_value};
|
||||||
use tracing::{error, warn};
|
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
|
/// Login request payload
|
||||||
#[derive(Serialize, Deserialize, utoipa::ToSchema)]
|
#[derive(Serialize, Deserialize, utoipa::ToSchema)]
|
||||||
@@ -81,7 +84,8 @@ pub async fn login(State(state): State<Arc<AppState>>, Json(payload): Json<Value
|
|||||||
.header(
|
.header(
|
||||||
SET_COOKIE,
|
SET_COOKIE,
|
||||||
format!(
|
format!(
|
||||||
"token={}; HttpOnly; Path=/; Max-Age={}; SameSite=Strict;",
|
"{}={}; HttpOnly; Path=/; Max-Age={}; SameSite=Strict;",
|
||||||
|
JWT_COOKIE_NAME,
|
||||||
jwt,
|
jwt,
|
||||||
claims.exp - claims.iat
|
claims.exp - claims.iat
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user