{"record":{"id":"6887deec7837e7c9","repo":"plandex-ai/plandex","slug":"error-refreshing-auth-auth-not-loaded","errorCode":null,"errorMessage":"error refreshing auth: auth not loaded","messagePattern":"error refreshing auth: auth not loaded","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/auth/auth.go","lineNumber":116,"sourceCode":"\t}\n\n\tif res.hasAccount {\n\t\treturn signIn(Current.Email, res.pin, Current.Host)\n\t} else {\n\t\thost := Current.Host\n\t\tif host == \"\" {\n\t\t\thost = \"Plandex Cloud\"\n\t\t}\n\n\t\tterm.OutputErrorAndExit(\"Account %s not found on %s\", Current.Email, host)\n\t}\n\n\treturn nil\n}\n\nfunc RefreshAuth() error {\n\tif Current == nil {\n\t\treturn fmt.Errorf(\"error refreshing auth: auth not loaded\")\n\t}\n\n\torg, apiErr := apiClient.GetOrgSession()\n\n\tif apiErr != nil {\n\t\treturn fmt.Errorf(\"error getting org session: %v\", apiErr.Msg)\n\t}\n\n\tCurrent.OrgName = org.Name\n\tCurrent.OrgIsTrial = org.IsTrial\n\tCurrent.IntegratedModelsMode = org.IntegratedModelsMode\n\n\terr := writeCurrentAuth()\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error writing auth: %v\", err)\n\t}\n","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/auth/auth.go#L98-L134","documentation":"RefreshAuth reloads the current org session and updates stored org metadata. It guards with `if Current == nil` because refresh requires the loaded auth context. If auth was never loaded (auth.json missing or load failed) it returns this error.","triggerScenarios":"refreshAuthIfNeeded calls RefreshAuth after a request, but `Current` is nil — MustResolveAuth never ran, auth.json was deleted, or an earlier unmarshal failure left Current unset.","commonSituations":"Auth file removed while CLI is running; invoking refresh logic from embedded/tests without sign-in; ordering bug in custom startup code.","solutions":["Ensure auth.MustResolveAuth completes before requests that can trigger refreshAuthIfNeeded","Re-run sign-in to recreate auth.json and set Current","Verify fs.HomeAuthPath exists, is readable, and unmarshals into shared.ClientAuth"],"exampleFix":"// before\norg, apiErr := apiClient.GetOrgSession() // via RefreshAuth: auth not loaded\n// after\nif auth.Current == nil {\n\tauth.MustResolveAuth(true)\n}\norg, apiErr := apiClient.GetOrgSession()","handlingStrategy":"validation","validationCode":"if auth.Current == nil {\n\treturn fmt.Errorf(\"cannot refresh auth: run sign-in first\")\n}","typeGuard":"func hasAuth() bool { return auth.Current != nil && auth.Current.OrgId != \"\" }","tryCatchPattern":"if err := auth.RefreshAuth(); err != nil {\n\tif strings.Contains(err.Error(), \"auth not loaded\") {\n\t\tauth.MustResolveAuth(true)\n\t} else {\n\t\tterm.OutputErrorAndExit(\"%v\", err)\n\t}\n}","preventionTips":["Initialize auth at CLI startup before any request","Don't remove or corrupt auth.json mid-session","Guard embedded refresh calls with a Current != nil check","Log auth load failures so Current==nil states are caught early"],"tags":["auth","session","refresh"],"backgroundTag":"auth-not-loaded","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"}