mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-28 04:59:52 +01:00
应用启动同步 localStorage token 到 store #3392
PR #3402 扩展:守卫放行后首次 API 请求时,vuex state.token 还是 null,httpRequest 读 store 取不到 Authorization 头,会被后端 401 → clearAuth 跳登录。在 main.js 应用启动阶段就把 localStorage 里的 token commit 进 store,避免 race。不动 refresh 链路与其它业务文件。
This commit is contained in:
parent
f492861f40
commit
7ed074d6e8
1 changed files with 7 additions and 0 deletions
|
|
@ -22,6 +22,13 @@ Vue.config.productionTip = false
|
||||||
// 注册Service Worker
|
// 注册Service Worker
|
||||||
registerServiceWorker();
|
registerServiceWorker();
|
||||||
|
|
||||||
|
// 应用启动时把 localStorage 里的 token 同步进 store,避免守卫放行后首次请求时
|
||||||
|
// httpRequest 读到 state.token=null 而漏带 Authorization 头触发 401 跳登录
|
||||||
|
const cachedToken = localStorage.getItem('token')
|
||||||
|
if (cachedToken) {
|
||||||
|
store.commit('setToken', cachedToken)
|
||||||
|
}
|
||||||
|
|
||||||
// 创建Vue实例
|
// 创建Vue实例
|
||||||
new Vue({
|
new Vue({
|
||||||
router,
|
router,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue