response contains username but jwt is holding username also
This commit is contained in:
@@ -18,6 +18,7 @@ pub struct Claims {
|
||||
pub sub: Uuid, // User ID
|
||||
pub exp: i64, // Expiration time
|
||||
pub role: String, // User role
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
pub fn init_jwt() -> Result<(), AuthError> {
|
||||
@@ -32,7 +33,7 @@ pub fn init_jwt() -> Result<(), AuthError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn generate_token(user_id: Uuid, role: &str) -> Result<String, AuthError> {
|
||||
pub fn generate_token(user_id: Uuid, role: &str, username: &str) -> Result<String, AuthError> {
|
||||
let keys = KEYS.get().ok_or(AuthError::ConfigError("JWT not initialized".to_string()))?;
|
||||
|
||||
let exp = OffsetDateTime::now_utc() + Duration::days(365000);
|
||||
@@ -40,6 +41,7 @@ pub fn generate_token(user_id: Uuid, role: &str) -> Result<String, AuthError> {
|
||||
sub: user_id,
|
||||
exp: exp.unix_timestamp(),
|
||||
role: role.to_string(),
|
||||
username: username.to_string(),
|
||||
};
|
||||
|
||||
encode(&Header::default(), &claims, &keys.encoding)
|
||||
|
||||
Reference in New Issue
Block a user