Skip to content

feat: clear Nuxt data on sign out and after sign-in/sign-up for a full page reload#49

Merged
JoachimLK merged 1 commit into
mainfrom
fix/force-full-page-reload
Feb 26, 2026
Merged

feat: clear Nuxt data on sign out and after sign-in/sign-up for a full page reload#49
JoachimLK merged 1 commit into
mainfrom
fix/force-full-page-reload

Conversation

@JoachimLK
Copy link
Copy Markdown
Contributor

@JoachimLK JoachimLK commented Feb 26, 2026

Summary

What does this PR change?

Adds clearNuxtData() before navigateTo() in three auth flows:

  • Sign-in (sign-in.vue) — after successful authClient.signIn.email()
  • Sign-up (sign-up.vue) — after successful authClient.signUp.email()
  • Sign-out (AppSidebar.vue) — after 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:

  • Sign-in: UI stuck on "Signing in…" — middleware still sees no session, blocks navigation to /dashboard
  • Sign-up: Redirects to /auth/sign-in instead of /onboarding/create-org — middleware sees stale unauthenticated state
  • Sign-out: Dashboard stays visible — middleware still sees the old authenticated session

Calling clearNuxtData() invalidates all useFetch/useAsyncData caches, 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

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Chore

Validation

  • I tested locally
  • I added/updated relevant documentation
  • I verified multi-tenant scoping and auth behavior for affected API paths

@railway-app railway-app Bot temporarily deployed to applirank / reqcore-pr-49 February 26, 2026 17:49 Destroyed
@railway-app
Copy link
Copy Markdown

railway-app Bot commented Feb 26, 2026

🚅 Deployed to the reqcore-pr-49 environment in applirank

Service Status Web Updated (UTC)
applirank ✅ Success (View Logs) Feb 26, 2026 at 5:53 pm

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 26, 2026

📝 Walkthrough

Walkthrough

Added calls to clearNuxtData() at three authentication state transitions: sign-out from the sidebar, post-sign-in navigation, and post-sign-up navigation. These additions ensure cached data is cleared before routing to new pages during auth flows.

Changes

Cohort / File(s) Summary
Auth State Transitions
app/components/AppSidebar.vue, app/pages/auth/sign-in.vue, app/pages/auth/sign-up.vue
Added clearNuxtData() calls to clear Nuxt cache at key authentication points: after sign-out, after successful sign-in, and before onboarding navigation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 When auth flows dance and tokens fade,
Clear the cache, fresh start is made,
Sign-out, sign-in, onboard anew—
Nuxt's memory wiped, just as true!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding clearNuxtData() calls in authentication flows to force full page reloads, which matches the actual changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The pull request description is comprehensive and well-structured, covering all required template sections with detailed explanations.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/force-full-page-reload

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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 | 🟠 Major

Handle thrown errors and always reset isLoading in sign-in flow.

Right now, only result.error clears 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 | 🟠 Major

Use try/catch/finally in 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.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cd200c8 and 0bdd9f5.

📒 Files selected for processing (3)
  • app/components/AppSidebar.vue
  • app/pages/auth/sign-in.vue
  • app/pages/auth/sign-up.vue

Comment on lines 18 to 23
async function handleSignOut() {
isSigningOut.value = true
await authClient.signOut()
clearNuxtData()
await navigateTo('/auth/sign-in')
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

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.

Suggested change
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.

@JoachimLK JoachimLK merged commit 0be66be into main Feb 26, 2026
4 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.

1 participant