From 9d8fa611b167246e5f9aa55936e3f2c8ecdf9247 Mon Sep 17 00:00:00 2001 From: Peter Vacho Date: Sun, 29 Dec 2024 23:54:36 +0100 Subject: [PATCH] Add endpoint to quickly get the current user --- src/api/users.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/api/users.py b/src/api/users.py index 031f6c4..802c5e0 100644 --- a/src/api/users.py +++ b/src/api/users.py @@ -105,6 +105,15 @@ async def get_users() -> list[UserData]: return [UserData.from_user(user) for user in users] +@protected_router.get("/me") +async def get_current_user(user: CurrentUserDep) -> UserData: + """Get the current user. + + This endpoint can also be used to check if the user is authenticated. + """ + return UserData.from_user(user) + + @protected_router.get("/{user_id}") async def get_user(user_id: PydanticObjectId) -> UserData: """Get a specific user."""