Alisa/crates/backend/src/auth.rs

27 lines
631 B
Rust
Raw Normal View History

2024-07-05 21:24:32 +02:00
use jsonwebtoken::{EncodingKey, Header, Validation};
use migration::token;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Deserialize, Serialize)]
struct Claims {
sub: Uuid,
name: String,
}
pub fn create_jwt(
user: entity::user::Model,
key: &EncodingKey,
) -> Result<String, jsonwebtoken::errors::Error> {
let claims = Claims {
sub: user.id,
name: user.name,
};
jsonwebtoken::encode(&Header::default(), &claims, key)
}
pub fn verify(token: &str) {
let validation = Validation::new(jsonwebtoken::Algorithm::HS256);
// jsonwebtoken::decode(token, , validation)
}