fastapi/full-stack-fastapi-template · error · HTTPException

User not found

Error message

User not found

What it means

Error "User not found" thrown in fastapi/full-stack-fastapi-template.

Source

Thrown at backend/app/api/deps.py:43

SessionDep = Annotated[Session, Depends(get_db)]
TokenDep = Annotated[str, Depends(reusable_oauth2)]


def get_current_user(session: SessionDep, token: TokenDep) -> User:
    try:
        payload = jwt.decode(
            token, settings.SECRET_KEY, algorithms=[security.ALGORITHM]
        )
        token_data = TokenPayload(**payload)
    except InvalidTokenError, ValidationError:
        raise HTTPException(
            status_code=status.HTTP_403_FORBIDDEN,
            detail="Could not validate credentials",
        )
    user = session.get(User, token_data.sub)
    if not user:
        raise HTTPException(status_code=404, detail="User not found")
    if not user.is_active:
        raise HTTPException(status_code=400, detail="Inactive user")
    return user


CurrentUser = Annotated[User, Depends(get_current_user)]


def get_current_active_superuser(current_user: CurrentUser) -> User:
    if not current_user.is_superuser:
        raise HTTPException(
            status_code=403, detail="The user doesn't have enough privileges"
        )
    return current_user

View on GitHub (pinned to 8063fe54f1)

When it happens

Trigger: Thrown at backend/app/api/deps.py:43 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of fastapi/full-stack-fastapi-template@8063fe54f1 (2026-08-26). Data as JSON: /api/errors/501d9b4e656ce8a2. Report an issue: GitHub.