the project uses token to authenticate users. I wrote in NuxtServerInit that the token stored in the Session of Node is written to Store, that is, after the user logs in, there are three places to store Session, Store and local localStorage, in the token,Node server. Now the problem is that when the user logs in somewhere else, the original token expires and the page is refreshed, I need to process the data in the axios response interceptor. If the returned code is 10004, Then clear the token, stored in the local, Store, and Node server Session, but the question is how to access the session?? in the Node server in axios Here is the code
import axios from "axios"
import { handleRequestParams, handleWebStorage } from "@/utils/utils"
import { WEBSTORAGE_TOKEN_NAME } from "@/config/config"
import state from "@/store/state"
import { apiByENV } from "@/config/config"
const Axios = axios.create({
baseURL: apiByENV,
timeout: 5000,
headers: {
"Content-Type": "application/x-www-form-urlencoded;charset=utf-8"
}
})
// http request()
Axios.interceptors.request.use(
config => {
if (state.KGUser && state.KGUser.token) {
config.headers.token = state.KGUser.token || ""
}
//
if (config.method === "post") {
config.data = handleRequestParams(config.data, config.headers.token)
}
return config
}, error => {
return Promise.reject(error)
}
)
// http response
Axios.interceptors.response.use(
response => {
// code10004tokenNodesessiontokenlocalStragetoken
if (response.code === "10004") {
}
return response
}, error => {
return Promise.reject(error)
}
)
export default Axios