Skip to content

Logic

logic.deps

logic.deps

get_current_user(token=Depends(oauth2_scheme))

Retrieves the current user from the token.

Source code in logic/deps.py
def get_current_user(token: str = Depends(oauth2_scheme)):
    """Retrieves the current user from the token."""
    username, password = decode_access_token(token)
    user = User.get(username)
    if not user or not user.verify_password(password):
        raise HTTPException(
            status_code=status.HTTP_401_UNAUTHORIZED,
            detail="Invalid user",
            headers={"WWW-Authenticate": "Bearer"},
        )
    private_key = user.get_private_key(password)
    return UserWithPrivateKey(user=user, private_key=private_key)