0

How to access $auth from a middleware with Nuxt ?

export default function ({ store, redirect }) {
  console.log(store.state.foo)
}
kissu
  • 40,416
  • 14
  • 65
  • 133
DevonDahon
  • 7,460
  • 6
  • 69
  • 114
  • Does this answer your question? [Nuxtjs Auth module not working in the middleware](https://stackoverflow.com/questions/64444811/nuxtjs-auth-module-not-working-in-the-middleware) – Iman Shafiei Apr 28 '21 at 18:05

2 Answers2

3

This one may work too I guess.

export default function ({ $auth })
kissu
  • 40,416
  • 14
  • 65
  • 133
0

This works but there might be a better answer.

export default function (context) {
  if (context.$auth.user.foo) {
    context.redirect('/bar')
  }
}
kissu
  • 40,416
  • 14
  • 65
  • 133
DevonDahon
  • 7,460
  • 6
  • 69
  • 114