nuxt-auth icon indicating copy to clipboard operation
nuxt-auth copied to clipboard

Signout with redirect causes flash of login page

Open hendrasan opened this issue 8 months ago • 4 comments

Environment



Reproduction

Describe the bug

I have:

/ -> landing page /login -> login page

And after login, when I logout, I want to log the user out to landing page, so I do this

await signOut({ callbackUrl: '/' })

But apparently, what it does is, the user is shown the login page for a bit, before being redirected to landing page.

Can we somehow change it? I tried this but it doesn't work

await signOut()
await navigateTo('/')

Additional context

No response

Logs


hendrasan avatar Jun 16 '25 11:06 hendrasan

@hendrasan Could you please share your config? What provider do you use?

phoenix-ru avatar Jun 27 '25 09:06 phoenix-ru

Hello 👋

Please provide a reproduction for this issue 🙏

How can I create a reproduction?

Please use one of the following links to reproduce your issue.

  • https://stackblitz.com/github/nuxt/starter/tree/v3-stackblitz
  • https://codesandbox.io/s/github/nuxt/starter/v3-codesandbox

Please ensure that the reproduction is as minimal as possible. This will allow us to isolate the issue as best as possible.

Here are some more amazing posts about the importance of reproductions:

github-actions[bot] avatar Jun 27 '25 09:06 github-actions[bot]

I'm using local provider, and my nuxt.config.ts is pretty basic, like this

auth: {
    globalAppMiddleware: true,
    sessionRefresh: {
      enableOnWindowFocus: false,
    },
    provider: {
      type: "local",
      token: {
        maxAgeInSeconds: 86400,
      },
      endpoints: {
        signIn: { path: "/auth/login", method: "post" },
        signOut: { path: "/auth/logout", method: "post" },
        signUp: { path: "/auth/register", method: "post" },
        getSession: { path: "/user/profile", method: "get" },
      },
    },
  },

on logout, I think the default is redirecting user to signIn (or maybe they're being redirected because of the absence of session data, hence middleware redirects them to signIn page.

The problem is when I do await signOut({ callbackUrl: '/' }), I guess the auth middleware is triggered first, hence showing a flash of signIn page, before the callbackUrl is being triggered.

hendrasan avatar Jun 27 '25 15:06 hendrasan

We encounter a very similar issue, where the global state is changed before the redirect, causing some UI flashing (certain colors/UI element change because they rely on some global state parts).

I think you're right that the middleware is triggered in the process of signing out.

TheDutchCoder avatar Aug 15 '25 15:08 TheDutchCoder