I am currently working with NuxtJS's auth module and attempting to retrieve the Bearer token along with a custom cookie that holds a sessionType during nuxtServerInit in order to update the store through a mutation. However, I am facing an issue where this only works when I refresh the page.
When I close the browser and navigate directly to my app URL, I consistently receive 'undefined' for auth._token.local because the nuxtServerInit function runs before the cookies are fully loaded.
The code snippet in my store/index.js file appears as follows:
export const actions = {
async nuxtServerInit({ commit, dispatch }, { req }) {
// Parse cookies using cookie-universal-nuxt
const token = this.$cookies.get('token')
const sessionType = this.$cookies.get('sessionType')
// Check if Cookie user and token exists to set them in 'auth'
if (token && user) {
commit('auth/SET_TOKEN', token)
commit('auth/SET_SESSION_TYPE', sessionType)
}
}
}
I am utilizing the nuxt-universal-cookies library.
Is there a method to delay the execution of the action until after the cookies have been successfully loaded in the browser?