Initial commit
This commit is contained in:
23
src/Routes/RouterAuhGuard.tsx
Normal file
23
src/Routes/RouterAuhGuard.tsx
Normal file
@@ -0,0 +1,23 @@
|
||||
import keycloak from "Api/Keycloak/Keycloak";
|
||||
import { useEffect, useRef } from "react";
|
||||
import { Outlet } from "react-router";
|
||||
|
||||
export default function AuthGuard() {
|
||||
const loginStarted = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!keycloak.authenticated && !loginStarted.current) {
|
||||
loginStarted.current = true;
|
||||
|
||||
keycloak.login({
|
||||
redirectUri: window.location.href,
|
||||
});
|
||||
}
|
||||
}, []);
|
||||
|
||||
if (!keycloak.authenticated) {
|
||||
return <div>Redirecting to login...</div>;
|
||||
}
|
||||
|
||||
return <Outlet />;
|
||||
}
|
||||
Reference in New Issue
Block a user