Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuxt Auth middleware not working on reload page #1586

Open
kiketordera opened this issue Nov 16, 2024 · 0 comments
Open

Nuxt Auth middleware not working on reload page #1586

kiketordera opened this issue Nov 16, 2024 · 0 comments

Comments

@kiketordera
Copy link

kiketordera commented Nov 16, 2024

Reproduction

Follow instructions with Latest version of nuxt, vuefire and nuxt-fire

Steps to reproduce the bug

This middleware won't work when you reload the page manually from the reload button of the browser of navigating to specific link:

// middleware/auth.ts
export default defineNuxtRouteMiddleware(async (to, from) => {
  const user = await getCurrentUser()

  // redirect the user to the login page
  if (!user) {
    return navigateTo({
      path: '/login',
      query: {
        redirect: to.fullPath,
      },
    })
  }
})

Expected behavior

When an user is logged in, it does not redirect to login page either navigating clicking either reloading or going to a specific URL directly

Actual behavior

When an user is logged in, it does not redirect to login page if we are navigating clicking
BUT IT DOES NOT WORK AS EXPECTED WHEN either reloading or going to a specific URL directly

Additional information

Problem is that the middleware does not wait to the user to be loaded from firebase, it executes before so the users is not loaded.

I have SSR Enabled in my nuxt.config.ts:

  routeRules: {
    "**": { prerender: true },
  },

If I change it and add the route I want to go a spa, the middleware actually works as expected in that specific route (in this case '/profile':

  routeRules: {
    "/profile": { prerender: false, ssr: false },
    "**": { prerender: true },
  },
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

No branches or pull requests

1 participant