This commit is contained in:
Miguel da Mota 2024-01-01 03:18:33 +01:00
parent 8a19a733d6
commit 52ef924f12
28 changed files with 577 additions and 170 deletions

View file

@ -9,18 +9,24 @@ pub fn get_user(req: HttpRequest) -> Result<Users, ErrorResponse> {
match authorization {
Some(header) => {
let claims = get_token(header.to_str().unwrap());
let token_data = get_token(header.to_str().unwrap());
match claims {
Ok(claims) => {
let user = Users::find(claims["user_id"].as_str())?;
match token_data {
Ok(token_data) => {
let user = Users::find(token_data.claims.user_id.as_str())?;
Ok(user)
}
Err(e) => {
return Err(ErrorResponse {
message: e.to_string(),
status: StatusCode::INTERNAL_SERVER_ERROR,
return Err(match e.kind() {
jsonwebtoken::errors::ErrorKind::ExpiredSignature => ErrorResponse {
message: "Not Authorized".to_string(),
status: StatusCode::UNAUTHORIZED,
},
_ => ErrorResponse {
message: e.to_string(),
status: StatusCode::INTERNAL_SERVER_ERROR,
},
})
}
}