fix: redirect authenticated users away from /login - #723
Conversation
The login page unconditionally cleared the auth token and query cache on every mount, forcing a re-login even when a valid session already existed. It now checks the stored token with getCurrentAdmin() (the same check the dashboard route loader uses) and redirects to the dashboard if it's still valid, only clearing the session when it's missing or invalid. The check is skipped for the Telegram MiniApp flow, which manages its own auth token independently. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Important Review skippedNo new commits to review since the last review. ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughThe login page separates route redirection from authentication cleanup, validates stored non-Telegram tokens with ChangesLogin session flow
Estimated code review effort: 2 (Simple) | ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@dashboard/src/pages/login.tsx`:
- Around line 157-168: Update the getCurrentAdmin effect to capture the current
auth token and create an AbortController for the request, ignoring aborted
requests and responses made with a stale token. In the catch handler, remove the
token and clear React Query state only when this request confirms a 401 or 403
authentication failure; preserve the current session for other HTTP errors, and
abort the controller during cleanup.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: ae82b83b-50a5-4fdb-9294-1fbb37f5f588
📒 Files selected for processing (1)
dashboard/src/pages/login.tsx
…e races getCurrentAdmin() rejected on any error (network blips, 5xx), which cleared a possibly-valid token on transient failures. Now only 401/403 responses clear the stored session. Also cancel the request on unmount via AbortController and re-check the stored token before acting, so a stale response can't clobber a token set by a concurrent login. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
@coderabbitai review |
✅ Action performedReview finished.
|
The login page unconditionally cleared the auth token and query cache on every mount, forcing a re-login even when a valid session already existed. It now checks the stored token with getCurrentAdmin() (the same check the dashboard route loader uses) and redirects to the dashboard if it's still valid, only clearing the session when it's missing or invalid. The check is skipped for the Telegram MiniApp flow, which manages its own auth token independently.
Summary
Type of change
Checklist
Summary by CodeRabbit