Static GitHub Issues

[2308] Middleware redirect infinity loop & Vuex Data not updating

prev: Putting a .ts file in middleware/ leads to death
next: nuxtServerInit Not Working with localhost:3000

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)
<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c2016">#c2016</a>)</em></sub></div>