I am using flask as my backend server. vuex action is not setting token from local storage state to Axios API call. Please help me with what am I missing. currently I am stuck here, this is related to my previous question which I dint get answer so posting again.. Below is my vuex store code:
Vue.use(Vuex); export default new Vuex.Store({ state: { // accessToken: JSON.parse(localStorage.getItem('access_token')) || null, // refreshToken: JSON.parse(localStorage.getItem('refresh_token')) || null, accessToken: localStorage.getItem('access_token') || null, refreshToken: localStorage.getItem('refresh_token') || null, APIData: '', }, actions: { refreshToken(context) { return new Promise((resolve, reject) => { console.log(context.state.refreshToken); getAPI.post('/refresh', { // refresh_token: context.state.refreshToken, headers: { Authorization: `Bearer ${context.state.refreshToken}` }, }) .then((response) => { console.log('New access token granted'); context.commit('updateAccessToken', response.data.access_token); console.log(context.state.accessToken); resolve(response.data.access_token); }) .catch((error) => { console.log('\'error in refresh:\'', error); reject(error); }); }); }, }
https://stackoverflow.com/questions/66974755/vuex-action-is-not-adding-localstorage-token-to-axios-post-call April 07, 2021 at 02:50AM
没有评论:
发表评论