This commit is contained in:
2026-06-09 23:05:35 +02:00
parent ee2fc42fff
commit eb2652f7e9
27 changed files with 665 additions and 538 deletions
+8 -11
View File
@@ -5,11 +5,9 @@ use uuid::Uuid;
#[derive(Debug, Serialize, Deserialize)]
pub struct Claims {
pub user_id: Uuid, // User ID
pub expire_at: usize, // Expiration time
pub created_at: usize, // Issued at
pub username: String,
pub is_superuser: bool, // Ajoutez ce champ
pub user_id: Uuid, // User ID
pub exp: usize, // Changé de expire_at -> exp (Standard JWT)
pub iat: usize, // Changé de created_at -> iat (Standard JWT)
}
pub fn create_jwt(
@@ -25,11 +23,9 @@ pub fn create_jwt(
.as_secs();
let claims = Claims {
user_id: user_id,
expire_at: (now + expiration_seconds) as usize,
created_at: now as usize,
username: username.to_string(),
is_superuser, // Et ici
user_id,
exp: (now + expiration_seconds) as usize,
iat: now as usize,
};
encode(
@@ -40,12 +36,13 @@ pub fn create_jwt(
}
pub fn verify_jwt(token: &str, secret: &str) -> Result<Claims, jsonwebtoken::errors::Error> {
println!("Verifying token: {}", token);
let validation = Validation::default();
let token_data = decode::<Claims>(
token,
&DecodingKey::from_secret(secret.as_ref()),
&validation,
)?;
println!("Token data: {:?}", token_data);
Ok(token_data.claims)
}