use crate::{
config,
support::{Jwt, UserClaims},
Auth, AuthResult,
};
impl Auth {
pub fn new(config: config::Auth) -> Self {
Self {
guard: Jwt::new(config.jwt),
}
}
pub fn authorize(&self, uid: String) -> AuthResult<String> {
self.guard.token(uid, None)
}
pub fn check(&self, token: &str) -> AuthResult<UserClaims> {
Ok(self.guard.validate(token)?.claims)
}
}
impl std::ops::Deref for Auth {
type Target = Jwt;
fn deref(&self) -> &Self::Target {
&self.guard
}
}