Refactor app instance to Keycloak SSO
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user