Add endpoint to quickly get the current user

This commit is contained in:
Peter Vacho 2024-12-29 23:54:36 +01:00
parent b1d3fa0600
commit 9d8fa611b1
Signed by: school
GPG key ID: 8CFC3837052871B4

View file

@ -105,6 +105,15 @@ async def get_users() -> list[UserData]:
return [UserData.from_user(user) for user in users] 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}") @protected_router.get("/{user_id}")
async def get_user(user_id: PydanticObjectId) -> UserData: async def get_user(user_id: PydanticObjectId) -> UserData:
"""Get a specific user.""" """Get a specific user."""