- chore: ran cargo fix on the codebase

This commit is contained in:
2025-03-07 21:03:15 -05:00
parent 3b789d0fd4
commit b6f2d3f456
59 changed files with 1324 additions and 523 deletions

View File

@@ -4,13 +4,17 @@ use std::env;
#[derive(Debug, Serialize, Deserialize)]
struct Claims {
sub: String, // Subject (user ID)
sub: String, // Subject (user ID)
session_id: String, // Session ID
roles: Vec<String>, // Roles/permissions
exp: usize, // Expiration time
exp: usize, // Expiration time
}
pub fn generate_token(user_id: &str, session_id: &str, roles: Vec<String>) -> Result<String, jsonwebtoken::errors::Error> {
pub fn generate_token(
user_id: &str,
session_id: &str,
roles: Vec<String>,
) -> Result<String, jsonwebtoken::errors::Error> {
let secret = env::var("JWT_SECRET").expect("JWT_SECRET must be set");
let expiration = chrono::Utc::now()
.checked_add_signed(chrono::Duration::days(1))
@@ -24,7 +28,11 @@ pub fn generate_token(user_id: &str, session_id: &str, roles: Vec<String>) -> Re
exp: expiration,
};
encode(&Header::default(), &claims, &EncodingKey::from_secret(secret.as_ref()))
encode(
&Header::default(),
&claims,
&EncodingKey::from_secret(secret.as_ref()),
)
}
pub fn validate_token(token: &str) -> Result<(String, String), jsonwebtoken::errors::Error> {