updatse
This commit is contained in:
parent
8a19a733d6
commit
52ef924f12
28 changed files with 577 additions and 170 deletions
|
@ -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,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue