I am using token based authentication instead of session based. The auth server is different from the nuxt.js app. Is there a way to add async functions to nuxtServerInit function. Given below is the code which I tried. But looks like its not waiting for the Promise to return.
`nuxtServerInit ({commit}, {req}) {
console.log('nuxtServer init');
let token = req.cookies.token;
let email = req.cookies.email;
return axios.post('https://my-server/api-token-verify/', {token: token}).then((response) => {
if (response.data.token) {
console.log('Token is valid');
commit('auth/setUser', {token, email});
return Promise.resolve();
} else {
commit('auth/setUser', null);
console.log('Invalid token');
return Promise.reject();
}
}).catch((err) => {
console.log('Invalid token');
return Promise.reject();
});
}`
<!--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/c221">#c221</a>)</em></sub></div>