fix: 增加重新登录意社区
This commit is contained in:
@@ -9,7 +9,7 @@ NProgress.configure({ showSpinner: false });
|
||||
const { getToken, logoutFun ,getRefreshToken} = useAuths();
|
||||
const whiteList = ["/login", "/auth-redirect", "/bind", "/register"];
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
NProgress.start();
|
||||
const hasToken = getToken();
|
||||
const refreshToken = getRefreshToken();
|
||||
@@ -18,8 +18,12 @@ router.beforeEach((to, from, next) => {
|
||||
const isPopup = window.opener && window.opener !== window;
|
||||
const clientId = urlParams.get('client_id');
|
||||
const redirectUri = urlParams.get('redirect_uri');
|
||||
// 检查是否已经处理过SSO登录(防重复)
|
||||
if (isPopup && clientId && redirectUri ) {
|
||||
// ➤ 如果是弹窗+LoginAgain,执行登出再跳转回 login 页面
|
||||
if (clientId === 'LoginAgain' && isPopup && hasToken) {
|
||||
await logoutFun()
|
||||
next({ path: '/login', query: { client_id: 'YiXinAi-Login', redirect_uri: redirectUri } });
|
||||
return;
|
||||
} else if (isPopup && clientId === 'YiXinAi-Login' && redirectUri) {
|
||||
if (hasToken) {
|
||||
// 发送消息给父窗口
|
||||
const targetOrigin = new URL(decodeURIComponent(redirectUri)).origin;
|
||||
@@ -30,6 +34,7 @@ router.beforeEach((to, from, next) => {
|
||||
}, targetOrigin);
|
||||
// 立即关闭窗口
|
||||
setTimeout(() => window.close(), 100);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,22 +42,22 @@ router.beforeEach((to, from, next) => {
|
||||
if (hasToken) {
|
||||
if (to.path === "/login") {
|
||||
// 已经登陆跳转到首页
|
||||
next({ path: "/" });
|
||||
next({path: "/"});
|
||||
NProgress.done();
|
||||
} else {
|
||||
if (useUserStore().roles.length === 0) {
|
||||
// 判断当前用户是否已拉取完user_info信息
|
||||
useUserStore()
|
||||
.getInfo()
|
||||
.then(() => {
|
||||
next({ ...to, replace: true });
|
||||
})
|
||||
.catch((err) => {
|
||||
logoutFun.then(() => {
|
||||
ElMessage.error(err);
|
||||
next({ path: "/" });
|
||||
.getInfo()
|
||||
.then(() => {
|
||||
next({...to, replace: true});
|
||||
})
|
||||
.catch((err) => {
|
||||
logoutFun.then(() => {
|
||||
ElMessage.error(err);
|
||||
next({path: "/"});
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user