Skip to main content

get_current_user

Decodes a JWT token to validate credentials and retrieves the corresponding active user from the database, raising HTTP exceptions if the token is invalid, the user is missing, or the account is inactive.

def get_current_user(
session: SessionDep,
token: TokenDep
) - > User

Validates the provided JWT token to retrieve and return the currently authenticated user from the database. Raises a 403 error for invalid tokens, a 404 if the user does not exist, and a 400 if the user account is inactive.

Parameters

NameTypeDescription
sessionSessionDepThe database session dependency used to query the user record.
tokenTokenDepThe encoded JWT access token used to identify and authenticate the user.

Returns

TypeDescription
UserThe User model instance representing the authenticated requester.