fix: 单点登录优化与环境变量完善
This commit is contained in:
@@ -12,35 +12,22 @@ const whiteList = ["/login", "/auth-redirect", "/bind", "/register"];
|
||||
router.beforeEach((to, from, next) => {
|
||||
NProgress.start();
|
||||
const hasToken = getToken();
|
||||
|
||||
if (to.path === "/login" || to.path === "/index") {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const isPopup = window.opener && window.opener !== window;
|
||||
const clientId = urlParams.get('client_id');
|
||||
const redirectUri = urlParams.get('redirect_uri');
|
||||
|
||||
// 检查是否已经处理过SSO登录(防重复)
|
||||
const hasHandledSSO = sessionStorage.getItem('sso_handled');
|
||||
if (isPopup && clientId && redirectUri && !hasHandledSSO) {
|
||||
if (isPopup && clientId && redirectUri ) {
|
||||
if (hasToken) {
|
||||
// 标记已处理,避免重复发送
|
||||
sessionStorage.setItem('sso_handled', 'true');
|
||||
|
||||
// 发送消息给父窗口
|
||||
const targetOrigin = new URL(decodeURIComponent(redirectUri)).origin;
|
||||
window.opener.postMessage({
|
||||
type: 'SSO_LOGIN_SUCCESS',
|
||||
token: hasToken
|
||||
}, redirectUri);
|
||||
|
||||
// 关闭弹出窗口
|
||||
}, targetOrigin);
|
||||
// 立即关闭窗口
|
||||
setTimeout(() => window.close(), 100);
|
||||
} else {
|
||||
// 存储SSO参数,但改用sessionStorage避免持久化
|
||||
sessionStorage.setItem('sso_params', JSON.stringify({
|
||||
isPopup,
|
||||
clientId,
|
||||
redirectUri
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user