- chore: ran cargo fix on the codebase
This commit is contained in:
@@ -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> {
|
||||
|
||||
Reference in New Issue
Block a user