Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nitinsinghnaruka's avatar

Nuxt JS auth middleware not working properly in ssr mode?

User is authenticated but in middleware auth state is undefined. When page is fully loaded is showing right information in vuex state tab.

0 likes
3 replies
kkhicher1's avatar
export default function (ctx) {
  if (ctx.app.$auth.$state.loggedIn) {
    return ctx.app.$auth.redirect('home')
  }
}

msyadav's avatar

@kkhicher1 While using context.app.$user.currentUser, it gives below error Cannot read property 'app' of undefined

msyadav's avatar

Use process.client as below

if (process.client && !store.state.user.currentUser) { return redirect('/auth') }

store state will only be available for if process.client is true.

Please or to participate in this conversation.