Updated auth checking roles

This commit is contained in:
Benjamin Sherriff
2023-10-18 16:38:04 -04:00
parent 1db5eade4e
commit 939f8c2b90
6 changed files with 79 additions and 22 deletions

View File

@@ -170,3 +170,14 @@ impl FromRequest for JwtAuth {
}
}
}
pub fn verify_role(auth: &JwtAuth, role: &str) -> Result<(), ServiceError> {
if auth.user.role == role {
Ok(())
} else {
Err(ServiceError {
status: 403,
message: "Forbidden".to_string()
})
}
}