-
Notifications
You must be signed in to change notification settings - Fork 0
fix: fix logout 2 #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR attempts to fix logout functionality by simplifying the logout flow and removing AceDataCloud OAuth-specific restrictions. However, the changes introduce several critical race conditions and bugs that could cause redirect loops and incorrect authentication state management.
Key Changes:
- Simplified logout mutation by removing query cache management
- Modified error handling in login status check to return
logged_in: truefor non-401 errors - Changed CSRF token cookie handling to use hardcoded cookie names instead of the configuration function
- Removed AceDataCloud OAuth-specific logout cookie and login restrictions on backend
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| web/service/use-common.ts | Simplified logout mutation (removed cache management) and modified error handling in useIsLogin to treat all non-401 errors as logged in |
| web/service/fetch.ts | Replaced CSRF_COOKIE_NAME() function call with hardcoded cookie name logic, duplicating configuration logic |
| web/app/signin/normal-form.tsx | Removed isFetching checks and modified redirect logic to skip default /apps redirect |
| web/app/components/header/account-dropdown/index.tsx | Changed logout from mutateAsync (awaited) to mutate (fire-and-forget), creating race conditions |
| api/controllers/console/auth/login.py | Removed no_acedatacloud_oauth cookie setting and OAuth login checks from email code login endpoints |
Comments suppressed due to low confidence (2)
web/app/components/header/account-dropdown/index.tsx:67
- This file uses
mutateAsyncand awaits the logout call before navigation, which is the correct pattern to avoid race conditions. The change inweb/app/components/header/account-dropdown/index.tsxto usemutatewithout waiting creates an inconsistency in how logout is handled across the codebase. See web/app/account/(commonLayout)/avatar.tsx:27-36, web/app/account/(commonLayout)/account-page/email-change-modal.tsx:171-179, and other files for the consistent pattern.
const { mutate: logout } = useLogout()
const handleLogout = () => {
logout()
resetUser()
localStorage.removeItem('setup_status')
// Tokens are now stored in cookies and cleared by backend
// To avoid use other account's education notice info
localStorage.removeItem('education-reverify-prev-expire-at')
localStorage.removeItem('education-reverify-has-noticed')
localStorage.removeItem('education-expired-has-noticed')
router.push('/signin')
}
web/app/components/header/account-dropdown/index.tsx:67
- Using
mutateinstead ofmutateAsyncmeans the logout API call is fired asynchronously but the code doesn't wait for it to complete before callingresetUser(), clearing localStorage, and navigating to/signin. This can cause a race condition where the user is redirected to the signin page while still having cached "logged in" state in React Query, potentially causing immediate redirect loops. Consider usingmutateAsyncand awaiting the logout, or adding anonSuccesscallback to handle the cleanup and navigation.
const { mutate: logout } = useLogout()
const handleLogout = () => {
logout()
resetUser()
localStorage.removeItem('setup_status')
// Tokens are now stored in cookies and cleared by backend
// To avoid use other account's education notice info
localStorage.removeItem('education-reverify-prev-expire-at')
localStorage.removeItem('education-reverify-has-noticed')
localStorage.removeItem('education-expired-has-noticed')
router.push('/signin')
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot 帮修复actions报错 |
Important
Fixes #<issue number>.Summary
Screenshots
Checklist
dev/reformat(backend) andcd web && npx lint-staged(frontend) to appease the lint gods