From 2541e3cd60acad79117c5f6d10fbdf86f3f8c7f6 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Thu, 1 Dec 2022 10:39:18 +0100 Subject: Use /me instead of all users --- server/src/routes/user.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'server/src') diff --git a/server/src/routes/user.rs b/server/src/routes/user.rs index d5a09e2..1bb56b9 100644 --- a/server/src/routes/user.rs +++ b/server/src/routes/user.rs @@ -8,15 +8,16 @@ use axum::{extract::Path, routing::get, Json, Router}; /// Create routes for `/v1/users/` namespace pub fn create_route() -> Router { Router::new() - .route("/", get(list_users)) + .route("/", get(get_me)) .route("/:id", get(get_user)) } -/// List users. Checks Authorization token -async fn list_users(_: Claims) -> Result>, AppError> { - let users = User::list().await?; - - Ok(Json(users)) +/// Get info about me +async fn get_me(claims: Claims) -> Result, AppError> { + match User::find_by_id(claims.user_id).await { + Ok(user) => Ok(Json(user)), + Err(_) => Err(AppError::NotFound("User not found".to_string())), + } } /// Search an user by `user_id`. It works only if the user passed by `Authorization` token is the -- cgit v1.2.3-18-g5258