You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
519 B

import { useStore } from "@nanostores/react";
import { Spin } from "antd";
import { Navigate } from "react-router-dom";
import { isAuthorized$, userInfoLoading$ } from "./stores/auth";
export function WithAuth(props) {
const isAuthorized = useStore(isAuthorized$);
const userInfoLoading = useStore(userInfoLoading$);
if (userInfoLoading) {
return <Spin className="user-info-loader" />;
}
if (isAuthorized) {
return <>{props.children}</>;
}
return <Navigate to="/signin" replace={true} />;
}