Get currnet user function

This commit is contained in:
2026-04-25 13:33:41 +02:00
parent c4d374dbfe
commit 834a0b7aa4
2 changed files with 17 additions and 2 deletions
+15 -1
View File
@@ -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,