Here is the code snippet I am using to manage login, logout, user retrieval, and token setting for all axios requests as an auth header.
While this code works perfectly during client-side rendering - such as logging in, storing the token in cookies, etc. - I encounter an issue when refreshing the page where it seems that the token is not being set anymore. Even calling the fetch action on NuxtServerInit doesn't help. Can anyone spot where my code might be going wrong?
This is the content of my store/index.js file:
https://jsfiddle.net/3dc07yv4/
import Cookie from 'cookie'
import Cookies from 'js-cookie'
export const state = () => ({
sidebar: true,
token: null,
user: null
})
export const mutations = {
// CODE FOR TOGGLING SIDEBAR, SETTING USER, AND TOKEN
}
...