Skip to content

Commit bcfaa8b

Browse files
committed
feat: Add JWT-based authentication and authorization module with token and secure cookie management.
1 parent eeacdd1 commit bcfaa8b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

backend/src/auth.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use axum::{
3131
use axum_extra::extract::cookie::{Cookie, CookieJar, SameSite};
3232
use chrono::{Duration, Utc};
3333
use jsonwebtoken::{decode, encode, DecodingKey, EncodingKey, Header, Validation};
34-
use once_cell::sync::Lazy;
34+
use std::sync::LazyLock;
3535
use serde::{Deserialize, Serialize};
3636
use std::sync::OnceLock;
3737
use std::collections::HashSet;
@@ -44,6 +44,12 @@ use crate::db::{self, DbPool};
4444
/// Initialized once at application startup via init_jwt_secret().
4545
pub static JWT_SECRET: OnceLock<String> = OnceLock::new();
4646

47+
/// Global storage for the JWT decoding key.
48+
/// Derived from JWT_SECRET once it's initialized.
49+
pub static DECODING_KEY: LazyLock<DecodingKey> = LazyLock::new(|| {
50+
DecodingKey::from_secret(get_jwt_secret().as_bytes())
51+
});
52+
4753
/// List of known placeholder secrets that must not be used in production.
4854
/// These are common defaults found in example configurations.
4955
const SECRET_BLACKLIST: &[&str] = &[

0 commit comments

Comments
 (0)