{"id":"8c93c3ab373f4bff","repo":"tiangolo/fastapi","slug":"inactive-user-8c93c3","errorCode":null,"errorMessage":"Inactive user","messagePattern":"Inactive user","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"docs_src/security/tutorial004_py310.py","lineNumber":114,"sourceCode":"        headers={\"WWW-Authenticate\": \"Bearer\"},\n    )\n    try:\n        payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])\n        username = payload.get(\"sub\")\n        if username is None:\n            raise credentials_exception\n        token_data = TokenData(username=username)\n    except InvalidTokenError:\n        raise credentials_exception\n    user = get_user(fake_users_db, username=token_data.username)\n    if user is None:\n        raise credentials_exception\n    return user\n\n\nasync def get_current_active_user(current_user: User = Depends(get_current_user)):\n    if current_user.disabled:\n        raise HTTPException(status_code=400, detail=\"Inactive user\")\n    return current_user\n\n\n@app.post(\"/token\")\nasync def login_for_access_token(\n    form_data: OAuth2PasswordRequestForm = Depends(),\n) -> Token:\n    user = authenticate_user(fake_users_db, form_data.username, form_data.password)\n    if not user:\n        raise HTTPException(\n            status_code=status.HTTP_401_UNAUTHORIZED,\n            detail=\"Incorrect username or password\",\n            headers={\"WWW-Authenticate\": \"Bearer\"},\n        )\n    access_token_expires = timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES)\n    access_token = create_access_token(\n        data={\"sub\": user.username}, expires_delta=access_token_expires\n    )","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/tiangolo/fastapi/blob/42a41db11f6882807ac3c057b942178d53b97438/docs_src/security/tutorial004_py310.py#L96-L132","documentation":"Default-parameter variant of error 50: `get_current_active_user` raises HTTP 400 'Inactive user' when `current_user.disabled` is True, after the JWT has been decoded and the user fetched. Runtime semantics are identical to the Annotated version.","triggerScenarios":"`GET /users/me/` with a valid JWT whose user has `disabled: True`.","commonSituations":"Account deactivated while JWTs remain valid; flag not reset on reactivation; identical to the Annotated twin.","solutions":["Authenticate as an active user.","Set `disabled` to `False` for the resolved user.","Show a clear disabled-account message; do not retry."],"exampleFix":"# before\n# JWT for a disabled user => 400\n# after\n# JWT for an active user => 200","handlingStrategy":"try-catch","validationCode":"None","typeGuard":"def is_inactive(resp) -> bool:\n    return getattr(resp, 'status_code', None) == 400 and resp.json().get('detail') == 'Inactive user'","tryCatchPattern":"try:\n    me = client.get('/users/me/', headers=auth_header(token))\n    me.raise_for_status()\nexcept httpx.HTTPStatusError as e:\n    if e.response.status_code == 400 and e.response.json().get('detail') == 'Inactive user':\n        prompt_reactivation()\n    raise","preventionTips":["Do not retry 'Inactive user' on the same token.","Rotate SECRET_KEY or denylist outstanding JWTs when disabling a user.","Keep the disabled flag in sync with admin tooling."],"tags":["authorization","security","jwt","user-management","fastapi"],"analyzedSha":"42a41db11f6882807ac3c057b942178d53b97438","analyzedAt":"2026-08-04T19:23:32.007Z","schemaVersion":2}