Skip to content

signOut() logout redirect silently fails #283

@onmax

Description

@onmax

signOut() with auth.redirects.logout configured doesn't navigate. The navigateTo call resolves but Vue Router drops the navigation because clearSession() triggers reactive updates in the same tick.

Reproduce

https://github.com/onmax/repros/tree/main/nuxt-better-auth-signout

git clone --depth 1 --filter=blob:none --sparse https://github.com/onmax/repros.git
cd repros && git sparse-checkout set nuxt-better-auth-signout
cd nuxt-better-auth-signout && pnpm i && BETTER_AUTH_SECRET=test-secret pnpm dev
  1. Sign up → lands on /dashboard
  2. Click "Sign out"
  3. Expected: redirect to /
  4. Actual: stays on /dashboard (session clears but no navigation)

This is more visible when reactive subscriptions (realtime queries, watchers) react to the auth state change during the same signOut flow.

Root cause

In signOut(), clearSession() triggers the internal watch(clientSession) watcher which fires synchronously. By the time navigateTo(logoutRedirect) executes, Vue Router has pending reactive updates and drops the navigation.

Suggested fix

// useUserSession.ts signOut()
 if (logoutRedirect)
+  await nextTick()
   await navigateTo(logoutRedirect)

nextTick() lets the reactive cascade from clearSession() settle before navigating.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions