Refactor app instance to Keycloak SSO

This commit is contained in:
2026-06-15 15:54:39 +08:00
parent fc9fd93c36
commit 461d1300ad
246 changed files with 1350 additions and 52721 deletions

View File

@ -2,8 +2,8 @@
import { useEffect } from 'react';
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
import { buildAuthPortalUrl } from '@/lib/auth-portal';
import { clearTokens, getMe, isLoggedIn } from '@/lib/api';
import { isKeycloakLogoutInProgress, startKeycloakLogin } from '@/lib/keycloak-oidc';
import { pickAppText } from '@/lib/i18n/core';
import { useAppI18n } from '@/lib/i18n/provider';
import { useChatStore } from '@/lib/store';
@ -71,13 +71,16 @@ export default function AuthGuard({
return;
}
const isPublicRoute = pathname === '/login' || pathname === '/register';
const isPublicRoute = pathname === '/login' || pathname === '/register' || pathname === '/auth/callback' || pathname === '/logout/callback';
const loggedIn = isLoggedIn();
if (!loggedIn && !isPublicRoute) {
if (isKeycloakLogoutInProgress()) {
return;
}
const search = searchParams?.toString();
const nextPath = search ? `${pathname}?${search}` : pathname;
window.location.replace(buildAuthPortalUrl('/login', nextPath));
void startKeycloakLogin(nextPath);
return;
}
@ -94,7 +97,7 @@ export default function AuthGuard({
);
}
const isPublicRoute = pathname === '/login' || pathname === '/register';
const isPublicRoute = pathname === '/login' || pathname === '/register' || pathname === '/auth/callback' || pathname === '/logout/callback';
if (!isPublicRoute && (!isLoggedIn() || !user)) {
return null;
}