feat: ai-hub与bbs单点登录联通

This commit is contained in:
Gsh
2025-06-21 21:52:44 +08:00
parent 7d902682f8
commit 8aaa22cea3
13 changed files with 206 additions and 39 deletions

View File

@@ -12,6 +12,39 @@ 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 (hasToken) {
// 标记已处理,避免重复发送
sessionStorage.setItem('sso_handled', 'true');
// 发送消息给父窗口
window.opener.postMessage({
type: 'SSO_LOGIN_SUCCESS',
token: hasToken
}, redirectUri);
// 关闭弹出窗口
setTimeout(() => window.close(), 100);
} else {
// 存储SSO参数但改用sessionStorage避免持久化
sessionStorage.setItem('sso_params', JSON.stringify({
isPopup,
clientId,
redirectUri
}));
}
}
}
if (hasToken) {
if (to.path === "/login") {
// 已经登陆跳转到首页