Initial commit: Clean workspace without heavy binaries
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
use jsonwebtoken::{encode, Header, EncodingKey};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
use chrono::{Utc, Duration};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Claims {
|
||||
pub sub: Uuid,
|
||||
pub exp: i64,
|
||||
pub role: String,
|
||||
}
|
||||
|
||||
pub fn create_jwt(user_id: Uuid, role: &str) -> Result<String, jsonwebtoken::errors::Error> {
|
||||
let expiration = Utc::now()
|
||||
.checked_add_signed(Duration::hours(24))
|
||||
.expect("valid timestamp")
|
||||
.timestamp();
|
||||
|
||||
let claims = Claims {
|
||||
sub: user_id,
|
||||
exp: expiration,
|
||||
role: role.to_string(),
|
||||
};
|
||||
|
||||
encode(&Header::default(), &claims, &EncodingKey::from_secret("secret".as_ref()))
|
||||
}
|
||||
Reference in New Issue
Block a user