Skip to content

Commit

Permalink
🌶feat:响应拦截requiresRelogin字段重新登陆
Browse files Browse the repository at this point in the history
  • Loading branch information
durunsong committed Nov 15, 2024
1 parent 0c4a7c7 commit 290a87f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/utils/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,23 @@ request.interceptors.response.use(
// 移除 pending 请求
removePendingRequest(response.config);

// 检查后端返回的 requiresRelogin 字段
console.log("requiresRelogin", response.data);
if (response.data?.requiresRelogin) {
// 退出登录并重定向到登录页面
logout();
// 弹出提示重新登录
ElNotification({
message: "用户信息已更新,请重新登录!",
type: "warning",
duration: 1.5 * 1000,
});
setTimeout(() => {
window.location.reload();
}, 1500);
return Promise.reject(new Error("用户信息已更新,请重新登录!"));
}

// 响应成功,返回数据
return response.data;
},
Expand Down

0 comments on commit 290a87f

Please sign in to comment.