fix: 单点登录优化与环境变量完善

This commit is contained in:
Gsh
2025-06-28 18:14:12 +08:00
parent 24d2908cca
commit 1d7a2013e3
11 changed files with 20 additions and 190 deletions

View File

@@ -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
}));
}
}
}