commit
f9d3fdd628
@ -1,21 +1,17 @@
|
||||
import { useStore } from "@nanostores/react";
|
||||
import { Spin } from "antd";
|
||||
|
||||
import { Navigate } from "react-router-dom";
|
||||
|
||||
import { isAuthorized$, userInfoLoading$ } from "./stores/auth";
|
||||
import { useKeycloak } from "@react-keycloak/web";
|
||||
|
||||
export function WithAuth(props) {
|
||||
const isAuthorized = useStore(isAuthorized$);
|
||||
const userInfoLoading = useStore(userInfoLoading$);
|
||||
const { keycloak } = useKeycloak();
|
||||
|
||||
if (userInfoLoading) {
|
||||
return <Spin className="user-info-loader" />;
|
||||
const login = async () => {
|
||||
await keycloak.login();
|
||||
}
|
||||
|
||||
if (isAuthorized) {
|
||||
if (keycloak.authenticated) {
|
||||
return <>{props.children}</>;
|
||||
} else {
|
||||
login()
|
||||
}
|
||||
|
||||
return <Navigate to="/signin" replace={true} />;
|
||||
return <></>;
|
||||
}
|
||||
|
||||
@ -0,0 +1,7 @@
|
||||
import Keycloak from "keycloak-js";
|
||||
|
||||
export const keycloak = new Keycloak({
|
||||
url: import.meta.env.VITE_KEYCLOAK_URL,
|
||||
realm: "SST",
|
||||
clientId: import.meta.env.VITE_KEYCLOAK_CLIENT_ID,
|
||||
});
|
||||
Loading…
Reference in new issue