Skip to content

Conversation

@nonhana
Copy link
Owner

@nonhana nonhana commented Jan 23, 2026

when sid expires, the logout api return 401 status; but 401 status trigger logout api again...


Note

Fixes logout 401 loop and unifies client re-login flow.

  • Backend (auth.controller.ts): Removed @UseGuards(AuthGuard) from POST /auth/logout and POST /auth/logout-all so they can succeed when the session is expired; both now always clear the session cookie after attempting logout.
  • Frontend (service): On 401 SESSION_EXPIRED, show a toast once and await userStore.logout(); removed inline router redirection logic.
  • Frontend (store): Added clearAuth(); logout() now clears local auth state and redirects to Login with a redirect back to the current route.

Written by Cursor Bugbot for commit 2fa1f4c. This will update automatically on new commits. Configure here.

@netlify
Copy link

netlify bot commented Jan 23, 2026

Deploy Preview for apiplayer ready!

Name Link
🔨 Latest commit 2fa1f4c
🔍 Latest deploy log https://app.netlify.com/projects/apiplayer/deploys/6973624df87ec9000865d82f
😎 Deploy Preview https://deploy-preview-2--apiplayer.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@nonhana nonhana self-assigned this Jan 23, 2026
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

This is the final PR Bugbot will review for you during this billing cycle

Your free Bugbot reviews will reset on February 7

Details

You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

}

/** 登出所有设备 */
@UseGuards(AuthGuard)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logout-all endpoint requires authentication but guard removed

High Severity

The logout-all endpoint had @UseGuards(AuthGuard) removed but still uses @ReqUser('id') to extract the user ID. Without the guard, request.user won't be populated by the authentication process, causing userId to be undefined. This results in destroyAllUserSessions(undefined), which creates a Redis key like user_sessions:undefined and returns 0 destroyed sessions instead of logging out all devices for the authenticated user. The endpoint completely fails to achieve its intended purpose.

Fix in Cursor Fix in Web

}

/** 用户登出 */
@UseGuards(AuthGuard)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logout endpoint cannot access session without guard

Medium Severity

After removing @UseGuards(AuthGuard), the logout endpoint can no longer access the session ID because request.sessionId is only populated by the guard. Without the guard, request.sessionId is undefined, so the if (sessionId) check fails and authService.logout(sessionId) is never called. This means sessions remain in the database indefinitely when users logout, even though the cookie is cleared. The endpoint should extract the session ID directly from request.cookies.sid to maintain full logout functionality.

Fix in Cursor Fix in Web

const userStore = useUserStore()
userStore.logout()
toast.error('登录已过期,请重新登录')

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Session expiration handling fails without navigation on error

Medium Severity

When a session expires, the interceptor now awaits userStore.logout() which handles both auth clearing and navigation internally. However, if the logout API call fails (network error, server down), the catch block in logout() silently swallows the error without calling clearAuth() or navigating. The old code called logout() without awaiting and handled navigation independently in the interceptor, guaranteeing the user would be redirected even if logout failed. Users now see "login expired" toast but remain stuck on the current page with stale auth state when logout fails.

Additional Locations (1)

Fix in Cursor Fix in Web

@nonhana nonhana merged commit a933bca into main Jan 23, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants