{"record":{"id":"26ca86f43b492e6d","repo":"plandex-ai/plandex","slug":"error-clearing-account-from-cookies","errorCode":null,"errorMessage":"Error clearing account from cookies: ","messagePattern":"Error clearing account from cookies: ","errorType":"http","errorClass":"http","httpStatus":500,"severity":"warning","filePath":"app/server/handlers/sessions.go","lineNumber":280,"sourceCode":"\tif err != nil {\n\t\tlog.Printf(\"Error deleting auth token: %v\\n\", err)\n\t\thttp.Error(w, \"Error deleting auth token: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\terr = ClearAuthCookieIfBrowser(w, r)\n\n\tif err != nil {\n\t\tlog.Printf(\"Error clearing auth cookie: %v\\n\", err)\n\t\thttp.Error(w, \"Error clearing auth cookie: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\terr = ClearAccountFromCookies(w, r, auth.User.Id)\n\n\tif err != nil {\n\t\tlog.Printf(\"Error clearing account from cookies: %v\\n\", err)\n\t\thttp.Error(w, \"Error clearing account from cookies: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tlog.Println(\"Successfully signed out\")\n}\n\nfunc GetOrgUserConfigHandler(w http.ResponseWriter, r *http.Request) {\n\tlog.Println(\"Received request for GetOrgUserConfigHandler\")\n\n\tauth := Authenticate(w, r, true)\n\tif auth == nil {\n\t\treturn\n\t}\n\n\torgUserConfig, err := db.GetOrgUserConfig(auth.User.Id, auth.OrgId)\n\n\tif err != nil {\n\t\tlog.Printf(\"Error getting org user config: %v\\n\", err)","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/sessions.go#L262-L298","documentation":"SignOutHandler reports HTTP 500 at app/server/handlers/sessions.go:276-281 when ClearAccountFromCookies returns an error while removing account-identifying cookies for auth.User.Id. Like the auth-cookie clear, this operates on response headers and fails when headers/body were already written or the helper errors internally.","triggerScenarios":"Sign-out request where the account-cookie clearing helper fails: response already committed, malformed cookie attributes, or helper-internal failure computing the cookie value for the given user id.","commonSituations":"Header already sent by earlier middleware, cookie set with a path/domain that the clear call does not match, or cookie names changed in a release so the clear helper no longer matches what was set.","solutions":["Check the logged 'Error clearing account from cookies: ...' text for http header-write errors","Verify the clear helper's cookie Name/Path/Domain exactly match those used when the cookie was set","Make sure nothing writes to w before this point in the request lifecycle","Treat as non-fatal: the server-side token is already deleted, so log and continue instead of returning 500"],"exampleFix":"// before\nerr = ClearAccountFromCookies(w, r, auth.User.Id)\nif err != nil {\n\thttp.Error(w, \"Error clearing account from cookies: \"+err.Error(), http.StatusInternalServerError)\n\treturn\n}\n// after\nerr = ClearAccountFromCookies(w, r, auth.User.Id)\nif err != nil {\n\tlog.Printf(\"Error clearing account from cookies: %v\\n\", err) // non-fatal\n}","handlingStrategy":"fallback","validationCode":"// server-side: confirm cookie attributes match before clearing\nconst accountCookiePath = \"/\" // must equal the path used at Set time","typeGuard":"func cookieExists(r *http.Request, name string) bool {\n\t_, err := r.Cookie(name)\n\treturn err == nil\n}","tryCatchPattern":"err := ClearAccountFromCookies(w, r, userID)\nif err != nil {\n\tlog.Printf(\"account cookie clear failed, falling back: %v\", err)\n\thttp.SetCookie(w, &http.Cookie{Name: \"account\", Value: \"\", Path: \"/\", MaxAge: -1})\n}","preventionTips":["Define cookie Name/Path/Domain constants in one place shared by set and clear code","Clear cookies before any body writes in the handler","Log and continue on cookie-clear failures; sign-out validity depends on server token deletion"],"tags":["go","http","cookies","session"],"backgroundTag":"cookie-clear-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}