Get currnet user function
This commit is contained in:
@@ -5,7 +5,7 @@ use argon2::{
|
||||
password_hash::{SaltString, rand_core::OsRng},
|
||||
};
|
||||
use axum::{
|
||||
Json,
|
||||
Extension, Json,
|
||||
extract::State,
|
||||
http::{Response, StatusCode, header},
|
||||
response::IntoResponse,
|
||||
@@ -155,6 +155,20 @@ pub async fn logout() -> Result<impl IntoResponse, (StatusCode, Json<serde_json:
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
pub async fn get_current_user(
|
||||
Extension(state): Extension<LoginModel>,
|
||||
) -> Result<impl IntoResponse, (StatusCode, Json<serde_json::Value>)> {
|
||||
let response = json!({
|
||||
"status": "success",
|
||||
"data": json!({
|
||||
"first_name": filter_users(&state).first_name,
|
||||
"last_name": filter_users(&state).last_name
|
||||
})
|
||||
});
|
||||
|
||||
Ok(Json(response))
|
||||
}
|
||||
|
||||
fn filter_users(user: &LoginModel) -> FilteredUser {
|
||||
FilteredUser {
|
||||
id: user.id,
|
||||
|
||||
Reference in New Issue
Block a user