{"record":{"id":"9b3b0f342b1c3937","repo":"invoke-ai/InvokeAI","slug":"user-not-found","errorCode":null,"errorMessage":"User not found","messagePattern":"User not found","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"invokeai/app/api/routers/auth.py","lineNumber":347,"sourceCode":"def get_current_user_info(\n    current_user: CurrentUser,\n) -> UserDTO:\n    \"\"\"Get current authenticated user's information.\n\n    Args:\n        current_user: The authenticated user's token data\n\n    Returns:\n        UserDTO containing user information\n\n    Raises:\n        HTTPException: 404 if user is not found (should not happen normally)\n    \"\"\"\n    user_service = ApiDependencies.invoker.services.users\n    user = user_service.get(current_user.user_id)\n\n    if user is None:\n        raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=\"User not found\")\n\n    return user\n\n\n@auth_router.post(\"/setup\", response_model=SetupResponse)\ndef setup_admin(\n    request: Annotated[SetupRequest, Body(description=\"Admin account details\")],\n) -> SetupResponse:\n    \"\"\"Set up initial administrator account.\n\n    This endpoint can only be called once, when no admin user exists. It creates\n    the first admin user for the system.\n\n    Args:\n        request: Admin account details (email, display_name, password)\n\n    Returns:\n        SetupResponse containing the created admin user","sourceCodeStart":329,"sourceCodeEnd":365,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/api/routers/auth.py#L329-L365","documentation":"get_current_user_info looks up the authenticated user's id via user_service.get(); if the store returns None it raises 404 'User not found'. Per the docstring this 'should not happen normally' — the auth dependency validated the token, but the underlying user record disappeared.","triggerScenarios":"GET /auth/me with a valid token whose user_id no longer exists in the users store (user deleted after token issuance, users DB replaced/reset).","commonSituations":"Admin deleted the user while their client still holds a valid token; database file swapped/recreated (fresh setup) while old tokens remain in a browser; multiuser store corruption or a different backend between requests.","solutions":["Re-login to obtain a token bound to an existing user (old token will keep failing)","Recreate the user with that id, or re-run /auth/setup to recreate the admin","If the DB was replaced, clear old tokens on clients","Check the users backend didn't get swapped/reset between requests"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"# verify the token still maps to a live user before relying on /auth/me\ndef token_user_missing(user: object | None) -> bool:\n    return user is None  # if a lookup returns None, the token's user_id is stale","typeGuard":"def user_exists(user: object | None) -> bool:\n    return user is not None and hasattr(user, 'user_id')","tryCatchPattern":"try:\n    resp = requests.get(f'{base}/auth/me', headers={'Authorization': f'Bearer {token}'})\n    resp.raise_for_status()\nexcept requests.HTTPError as e:\n    if e.response.status_code == 404:\n        clear_stored_token()\n        relogin()  # token points to a deleted user; start a fresh session","preventionTips":["Invalidate client sessions when deleting users server-side","Re-setup/re-login after replacing or resetting the users database","Treat 404 on /auth/me as 'session invalid' and force re-login","Avoid swapping user-store backends while clients hold tokens"],"tags":["http-404","authentication","stale-token"],"backgroundTag":"stale-token-user-deleted","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}