{"record":{"id":"03cc2794bb5590ee","repo":"plandex-ai/plandex","slug":"user-not-found","errorCode":null,"errorMessage":"user not found","messagePattern":"user not found","errorType":"exception","errorClass":null,"httpStatus":404,"severity":"error","filePath":"app/server/handlers/auth_helpers.go","lineNumber":319,"sourceCode":"\n\tif req.IsSignInCode {\n\t\tres, err := db.ValidateSignInCode(req.Pin)\n\n\t\tif err != nil {\n\t\t\tlog.Printf(\"Error validating sign in code: %v\\n\", err)\n\t\t\treturn nil, fmt.Errorf(\"error validating sign in code: %v\", err)\n\t\t}\n\n\t\tuser, err = db.GetUser(res.UserId)\n\n\t\tif err != nil {\n\t\t\tlog.Printf(\"Error getting user: %v\\n\", err)\n\t\t\treturn nil, fmt.Errorf(\"error getting user: %v\", err)\n\t\t}\n\n\t\tif user == nil {\n\t\t\tlog.Printf(\"User not found for id: %v\\n\", res.UserId)\n\t\t\treturn nil, fmt.Errorf(\"user not found\")\n\t\t}\n\n\t\tsignInCodeId = res.Id\n\t\tsignInCodeOrgId = res.OrgId\n\t} else {\n\t\treq.Email = strings.ToLower(req.Email)\n\t\tuser, err = db.GetUserByEmail(req.Email)\n\n\t\tif err != nil {\n\t\t\tlog.Printf(\"Error getting user: %v\\n\", err)\n\t\t\treturn nil, fmt.Errorf(\"error getting user: %v\", err)\n\t\t}\n\n\t\tif user == nil {\n\t\t\tlog.Printf(\"User not found for email: %v\\n\", req.Email)\n\t\t\treturn nil, fmt.Errorf(\"not found\")\n\t\t}\n","sourceCodeStart":301,"sourceCodeEnd":337,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/auth_helpers.go#L301-L337","documentation":"ValidateAndSignIn, sign-in-code branch: db.GetUser(res.UserId) returned nil for the user id stored on a validated sign-in code. The code was valid but the user record was deleted — an orphaned sign-in code.","triggerScenarios":"Client redeems a sign-in code whose res.UserId points at a user row that no longer exists; db.GetUser returns (nil, nil).","commonSituations":"User deleted after the sign-in code was issued; cross-environment DB (staging code against prod data); user purged by a cleanup job while codes persist.","solutions":["Delete or regenerate the sign-in code; have the user restart the sign-in flow","Check for user-deletion jobs or cascades that leave orphaned sign-in codes","Verify the server is pointed at the expected database/environment","Log res.UserId and confirm the row exists directly in the users table"],"exampleFix":"// before\nif user == nil {\n\treturn nil, fmt.Errorf(\"user not found\")\n}\n// after\nif user == nil {\n\tlog.Printf(\"orphaned sign-in code userId=%v\", res.UserId)\n\treturn nil, fmt.Errorf(\"user not found\")\n}","handlingStrategy":"validation","validationCode":"// before redeeming codes, clean orphans periodically\nSELECT c.id FROM sign_in_codes c LEFT JOIN users u ON u.id = c.user_id WHERE u.id IS NULL;","typeGuard":"func isOrphanedCode(res *db.ValidateCodeResult) bool {\n\tu, _ := db.GetUser(res.UserId)\n\treturn u == nil\n}","tryCatchPattern":"user, err := ValidateAndSignIn(w, r, req)\nif err != nil {\n\tif err.Error() == \"user not found\" {\n\t\thttp.Error(w, \"this sign-in code is no longer valid, restart sign-in\", http.StatusGone)\n\t\treturn\n\t}\n\thttp.Error(w, err.Error(), http.StatusUnauthorized)\n}","preventionTips":["Cascade-delete sign-in codes when users are deleted","Regenerate codes rather than persisting them indefinitely","Verify environment alignment (staging code vs prod DB) during debugging","Treat 'user not found' as a restart-sign-in signal on the client"],"tags":["auth","signin","user-not-found"],"backgroundTag":"user-not-found","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}