Added auth to endpoints

This commit is contained in:
Benjamin Sherriff
2023-10-18 15:36:36 -04:00
parent 7ba0e070ac
commit f072a47d22
12 changed files with 160 additions and 84 deletions

View File

@@ -79,9 +79,30 @@ impl InsertUser {
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ResponseUser {
pub email: String,
pub role: String,
pub first_name: String,
pub last_name: String,
}
impl From<QueryUser> for ResponseUser {
fn from(user: QueryUser) -> Self {
ResponseUser {
email: user.email,
role: user.role,
first_name: user.first_name,
last_name: user.last_name,
}
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct JwtAuth {
pub access_token_uuid: uuid::Uuid
pub access_token_uuid: uuid::Uuid,
pub email: String,
pub role: String,
}
impl FromRequest for JwtAuth {
@@ -140,8 +161,8 @@ impl FromRequest for JwtAuth {
};
match QueryUser::get_by_email(&user_email) {
Ok(_) => {
ready(Ok(JwtAuth { access_token_uuid }))
Ok(user) => {
ready(Ok(JwtAuth { access_token_uuid, email: user.email, role: user.role }))
}
Err(err) => return ready(Err(ActixError::from(ServiceError {
status: 500,