feat: clear Nuxt data on sign out and after sign-in/sign-up for a full page reload#49
Conversation
|
🚅 Deployed to the reqcore-pr-49 environment in applirank
|
📝 WalkthroughWalkthroughAdded calls to Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 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.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
app/pages/auth/sign-in.vue (1)
25-48:⚠️ Potential issue | 🟠 MajorHandle thrown errors and always reset
isLoadingin sign-in flow.Right now, only
result.errorclears loading. A thrown error on Line 35, Line 46, or Line 47 can leave the form stuck.💡 Proposed fix
async function handleSignIn() { error.value = '' @@ isLoading.value = true - - const result = await authClient.signIn.email({ - email: email.value, - password: password.value, - }) - - if (result.error) { - error.value = result.error.message ?? 'Invalid credentials. Please try again.' - isLoading.value = false - return - } - - clearNuxtData() - await navigateTo('/dashboard') + try { + const result = await authClient.signIn.email({ + email: email.value, + password: password.value, + }) + + if (result.error) { + error.value = result.error.message ?? 'Invalid credentials. Please try again.' + return + } + + clearNuxtData() + await navigateTo('/dashboard') + } catch { + error.value = 'Sign-in failed. Please try again.' + } finally { + isLoading.value = false + } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@app/pages/auth/sign-in.vue` around lines 25 - 48, The sign-in flow in handleSignIn can leave isLoading.value true if authClient.signIn.email, clearNuxtData(), or navigateTo() throws; wrap the await calls in a try/catch/finally so thrown errors set error.value appropriately (use the caught error.message or a fallback) and ensure isLoading.value is reset in the finally block, keeping the existing result.error handling intact; update references in handleSignIn to call authClient.signIn.email, clearNuxtData, and navigateTo inside the try and reset isLoading in finally.app/pages/auth/sign-up.vue (1)
20-54:⚠️ Potential issue | 🟠 MajorUse
try/catch/finallyin sign-up so loading state always recovers.A thrown failure on Line 40, Line 52, or Line 53 bypasses the current reset path and can lock the form in loading state.
💡 Proposed fix
async function handleSignUp() { error.value = '' @@ isLoading.value = true - - const result = await authClient.signUp.email({ - email: email.value, - password: password.value, - name: name.value, - }) - - if (result.error) { - error.value = result.error.message ?? 'Sign-up failed. Please try again.' - isLoading.value = false - return - } - - clearNuxtData() - await navigateTo('/onboarding/create-org') + try { + const result = await authClient.signUp.email({ + email: email.value, + password: password.value, + name: name.value, + }) + + if (result.error) { + error.value = result.error.message ?? 'Sign-up failed. Please try again.' + return + } + + clearNuxtData() + await navigateTo('/onboarding/create-org') + } catch { + error.value = 'Sign-up failed. Please try again.' + } finally { + isLoading.value = false + } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@app/pages/auth/sign-up.vue` around lines 20 - 54, handleSignUp can throw before isLoading is reset; wrap the async logic in a try/catch/finally inside the handleSignUp function so any thrown error is caught and isLoading.value is always restored. Specifically, call isLoading.value = true before the try, move the authClient.signUp.email call and subsequent result handling into the try block, set error.value inside the catch using the caught error message (fall back to a generic message), and set isLoading.value = false in the finally block; keep calls to clearNuxtData() and navigateTo('/onboarding/create-org') in the try after successful sign-up to preserve existing flow.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@app/components/AppSidebar.vue`:
- Around line 18-23: The sign-out flow in handleSignOut sets isSigningOut.value
= true but doesn't reset it if authClient.signOut(), clearNuxtData(), or
navigateTo('/auth/sign-in') throws; wrap the main logic in a try/finally so
isSigningOut.value is reset in the finally block (optionally catch/log errors
from authClient.signOut/clearNuxtData/navigateTo before rethrowing) to ensure
the disabled state never gets stuck.
---
Outside diff comments:
In `@app/pages/auth/sign-in.vue`:
- Around line 25-48: The sign-in flow in handleSignIn can leave isLoading.value
true if authClient.signIn.email, clearNuxtData(), or navigateTo() throws; wrap
the await calls in a try/catch/finally so thrown errors set error.value
appropriately (use the caught error.message or a fallback) and ensure
isLoading.value is reset in the finally block, keeping the existing result.error
handling intact; update references in handleSignIn to call
authClient.signIn.email, clearNuxtData, and navigateTo inside the try and reset
isLoading in finally.
In `@app/pages/auth/sign-up.vue`:
- Around line 20-54: handleSignUp can throw before isLoading is reset; wrap the
async logic in a try/catch/finally inside the handleSignUp function so any
thrown error is caught and isLoading.value is always restored. Specifically,
call isLoading.value = true before the try, move the authClient.signUp.email
call and subsequent result handling into the try block, set error.value inside
the catch using the caught error message (fall back to a generic message), and
set isLoading.value = false in the finally block; keep calls to clearNuxtData()
and navigateTo('/onboarding/create-org') in the try after successful sign-up to
preserve existing flow.
| async function handleSignOut() { | ||
| isSigningOut.value = true | ||
| await authClient.signOut() | ||
| clearNuxtData() | ||
| await navigateTo('/auth/sign-in') | ||
| } |
There was a problem hiding this comment.
Guard sign-out flow with try/finally to prevent a stuck disabled button.
If Line 20, Line 21, or Line 22 throws, isSigningOut never resets and the action remains disabled.
💡 Proposed fix
async function handleSignOut() {
isSigningOut.value = true
- await authClient.signOut()
- clearNuxtData()
- await navigateTo('/auth/sign-in')
+ try {
+ await authClient.signOut()
+ clearNuxtData()
+ await navigateTo('/auth/sign-in')
+ } finally {
+ isSigningOut.value = false
+ }
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| async function handleSignOut() { | |
| isSigningOut.value = true | |
| await authClient.signOut() | |
| clearNuxtData() | |
| await navigateTo('/auth/sign-in') | |
| } | |
| async function handleSignOut() { | |
| isSigningOut.value = true | |
| try { | |
| await authClient.signOut() | |
| clearNuxtData() | |
| await navigateTo('/auth/sign-in') | |
| } finally { | |
| isSigningOut.value = false | |
| } | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@app/components/AppSidebar.vue` around lines 18 - 23, The sign-out flow in
handleSignOut sets isSigningOut.value = true but doesn't reset it if
authClient.signOut(), clearNuxtData(), or navigateTo('/auth/sign-in') throws;
wrap the main logic in a try/finally so isSigningOut.value is reset in the
finally block (optionally catch/log errors from
authClient.signOut/clearNuxtData/navigateTo before rethrowing) to ensure the
disabled state never gets stuck.
Summary
What does this PR change?
Adds
clearNuxtData()beforenavigateTo()in three auth flows:authClient.signIn.email()authClient.signUp.email()authClient.signOut()Why is this needed?
All auth middleware (auth.ts, guest.ts, require-org.ts) checks session state via
authClient.useSession(useFetch), which caches results through Nuxt's data-fetching layer. After auth state changes (sign-in/sign-up/sign-out), the cookie updates but the cached session data remains stale. This causes:/dashboard/auth/sign-ininstead of/onboarding/create-org— middleware sees stale unauthenticated stateCalling
clearNuxtData()invalidates alluseFetch/useAsyncDatacaches, forcing middleware to fetch fresh session data on the next navigation. This fixes all three issues without resorting to full page reloads (external: true), preserving smooth client-side transitions.This is the proper fix for the issue reported in PR #43.
Type of change
Validation