summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2022-10-18 21:14:28 +0200
committerSanto Cariotti <santo@dcariotti.me>2022-10-18 21:14:28 +0200
commit2a3ac944339ad34ef74f0aede7faceb06d4abeae (patch)
treee78dba7bc70e70f1178401dde134d351f4f010a6 /server
parent2845a79b1ffc04600b270bc8ef452763cbefd117 (diff)
Add /me endpoint
Diffstat (limited to 'server')
-rw-r--r--server/src/routes/user.rs8
1 files 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<i32>, _: Claims) -> Result<Json<UserList>, AppError> {
- match User::find_by_id(user_id).await {
+/// Get the user from the `Authorization` header token
+async fn get_user(claims: Claims) -> Result<Json<UserList>, AppError> {
+ match User::find_by_id(claims.user_id).await {
Ok(user) => Ok(Json(user)),
Err(_) => Err(AppError::NotFound),
}