From 2a3ac944339ad34ef74f0aede7faceb06d4abeae Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Tue, 18 Oct 2022 21:14:28 +0200 Subject: Add /me endpoint --- server/src/routes/user.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/src/routes/user.rs b/server/src/routes/user.rs index d44df66..a3d7a5e 100644 --- a/server/src/routes/user.rs +++ b/server/src/routes/user.rs @@ -9,7 +9,7 @@ use axum::{extract::Path, routing::get, Json, Router}; pub fn create_route() -> Router { Router::new() .route("/", get(list_users).post(create_user)) - .route("/:id", get(get_user)) + .route("/me", get(get_user)) } /// List users. Checks Authorization token @@ -30,9 +30,9 @@ async fn create_user( Ok(Json(user_new)) } -/// Get an user with id = `user_id`. Checks Authorization token -async fn get_user(Path(user_id): Path, _: Claims) -> Result, AppError> { - match User::find_by_id(user_id).await { +/// Get the user from the `Authorization` header token +async fn get_user(claims: Claims) -> Result, AppError> { + match User::find_by_id(claims.user_id).await { Ok(user) => Ok(Json(user)), Err(_) => Err(AppError::NotFound), } -- cgit v1.2.3-18-g5258