fix(auth): retry user initialization before clearing session#5814
fix(auth): retry user initialization before clearing session#5814rogeecn wants to merge 1 commit intousememos:mainfrom
Conversation
📝 WalkthroughWalkthroughA new retry utility for authentication initialization with exponential backoff is introduced and integrated into AuthContext, wrapping the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3820a8c523
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } catch (error) { | ||
| if (attempt >= AUTH_INIT_MAX_RETRIES) { | ||
| throw error; | ||
| } | ||
| await sleep(delayMs); |
There was a problem hiding this comment.
Avoid retrying terminal unauthenticated failures
retryAuthInitialization() retries every thrown error, including ConnectError unauthenticated cases that are already handled in the auth interceptor (shouldHandleUnauthenticatedRetry in web/src/connect.ts) and indicate the session is gone. In that path, this loop adds 500ms+1000ms+2000ms delay before clearing state, so users with revoked/invalid sessions wait ~3.5s longer to reach signed-out UI (or redirect), which is a regression from the previous immediate fallback behavior.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
web/src/contexts/AuthContext.tsx (1)
8-8: Use@/alias for consistency with other imports.As per coding guidelines, use the
@/alias for absolute imports in the frontend instead of relative paths.♻️ Proposed fix
-import { retryAuthInitialization } from "./auth-initialize"; +import { retryAuthInitialization } from "@/contexts/auth-initialize";🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@web/src/contexts/AuthContext.tsx` at line 8, Replace the relative import of retryAuthInitialization in AuthContext.tsx with the project alias form; change the import path from "./auth-initialize" to use the "@/..." alias (e.g. "@/contexts/auth-initialize") so the statement importing retryAuthInitialization uses the alias-consistent path.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@web/src/contexts/AuthContext.tsx`:
- Line 8: Replace the relative import of retryAuthInitialization in
AuthContext.tsx with the project alias form; change the import path from
"./auth-initialize" to use the "@/..." alias (e.g. "@/contexts/auth-initialize")
so the statement importing retryAuthInitialization uses the alias-consistent
path.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4c54f2c1-cff1-4e35-a8fc-26782d86220a
📒 Files selected for processing (3)
web/src/contexts/AuthContext.tsxweb/src/contexts/auth-initialize.tsweb/test/auth-initialize.test.mjs
Summary
Test Plan
Summary by CodeRabbit
Bug Fixes
Tests