Skip to content

Middleware redirect infinity loop & Vuex Data not updating #2308

Closed
@fahidmohammad

Description

I'm using auth route with middleware and when using the below snippet the application going on a infinity loop.

export default function ({ store, redirect, error }) {
  console.log('store.state.authUser',store.state.authUser);
  if (store.state.authUser!=null) {
	  console.log('inside null')
	  redirect('/secret')
  }
}

Login View
image

Successful Login
image

When clicking the link

image

The same route when accessed using direct url its working fine. But not when using
<nuxt-link to="/secret">Super secret page</nuxt-link>

Update:

Also the store.state.authUser is globally accessible across different browser, when using with express.

Express Code below:

let config = require('./nuxt.config.js')

config.dev = !(process.env.NODE_ENV === 'production')

// Init Nuxt.js
const nuxt = new Nuxt(config)

// Build only in dev mode
if (config.dev) {
  const builder = new Builder(nuxt)
  builder.build()
}
// Give nuxt middleware to express
app.use(nuxt)
This question is available on Nuxt.js community (#c2016)

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions