-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
双token过期问题 #493
Comments
过期你只要请求就会重新刷新 |
也就是后端要设计成无论refreshToken有没有过期,都可以刷新请求才行?我后端目前是refreshToken过期了就要重新通过login去获取双token @xiaoxian521 |
目前平台是 |
是这样的,我后端是有jwt验证的,后端也会再次验证一次token,如果token过期会返回401错误,虽然平台会触发刷新token,但是我后端检测到token是过期的,就会返回401,这样平台是拿不到token返回的,按理来说,检测到后端返回401就需要返回登录页的 |
在签发token时生成两个token,accessToken和refreshToken,前端每次请求时携带accessToken,后端发现accessToken过期时,返回token已过期的结果。前端根据后端状态码判断token是否已经过期,如果过期则携带refreshToken请求刷新token的接口,如果refreshToken没有过期,则后端重新生成accessToken和refreshToken返回给前端,到这里都没有问题,如果refreshToken也过期了,则返回结果要求前端重新登录,我们平台在这一步没有返回登陆页面,一直卡在加载左侧菜单栏。 |
这就是你自己的业务逻辑了 很简单自行处理哈 |
我是个新手~ 这种情况别人大概是什么样的逻辑,如果可以的话,还要麻烦你给点提示 |
我目前用的就是这种方法,但是,会报错:[Vue warn]: Maximum recursive updates exceeded in component <sidebarItem>. This means you have a reactive effect that is mutating its own dependencies and thus recursively triggering itself. Possible sources include component template, render function, updated hook or watcher source function. |
/** 响应拦截 */ 要加 location.reload(); 强行刷新才正常,但是这样影响体验,所以才来开issue问问~ |
贴代码贴完整哈 |
在src/utils/http/index.ts 下,其他代码我都没改动过,只新增了这3行 |
你可以试试,拦截响应加了 logout() 以后,登录完停留在首页 http://localhost:8848/#/welcome ,在这里等超时,按F5刷新,再登录,就会出现。我用非国际精简版,除了用户是从后端返回的外,其他没更改,也会出现这种情况。 |
我能力有限,目前能定位到,src/layout/components/sidebar/sidebarItem.vue 的大概底151行左右的 hasOneShowingChild 这个函数,if (showingChildren.length === 0) 这里会出现这种递归循环,但是不知道怎么修改 |
logout() 函数里面 router.push("/login"); 替换成 window.location.href = "/"; 问题解决。 |
refreshToken过期,那一定会走到用refreshToken换取accessToken 所以只需要在这个请求的结果中进行处理即可。 我是这么改的,在 /** 刷新`token` */
async handRefreshToken(data) {
return new Promise<RefreshTokenResult>((resolve, reject) => {
refreshTokenApi(data)
.then(data => {
if (data?.code === 0) {
setToken(data.data);
resolve(data);
} else {
message(data.msg, { type: "error" });
removeToken();
router.push("/login");
}
})
.catch(error => {
reject(error);
});
});
} |
假如浏览器一直不关闭,refreshToken过期了以后,平台不会跳转到登录页面,会一直卡在加载左侧菜单栏的页面,只能退出登录重新登录才行,这是bug吗

The text was updated successfully, but these errors were encountered: