Reputation: 1758
I'm trying to set up Firebase Auth with Vuex and Nuxt using this tutorial. However if I console.log(req)
it's undefined
In the tutorial the vuex action is:
nuxtServerInit ({ commit }, { req }) {
if (req.session && req.session.authUser) {
commit(‘SET_USER’, req.session.authUser)
req.session.cookie=”” + req.session.authUser
}
}
But no where in the tutorial was it actually defined. Even straight from the docs they have:
actions: {
nuxtServerInit ({ commit }, { req }) {
if (req.session.user) {
commit('user', req.session.user)
}
}
}
But I can't find where you initially set req
or how to access it in the Vuex store
Upvotes: 0
Views: 614
Reputation: 522
You need to create a store/index.js file and define the nuxtServerInit action in there as you have in your second example.
https://nuxtjs.org/docs/2.x/directory-structure/store/#the-nuxtserverinit-action
Upvotes: 1