2021-06-18 20:07:26 +01:00
|
|
|
import { Redirect } from "react-router-dom";
|
|
|
|
|
2021-07-05 11:23:23 +01:00
|
|
|
import { useContext } from "preact/hooks";
|
|
|
|
|
|
|
|
import { Children } from "../../types/Preact";
|
2021-06-19 18:46:05 +01:00
|
|
|
import { OperationsContext } from "./RevoltClient";
|
2021-06-18 20:07:26 +01:00
|
|
|
|
|
|
|
interface Props {
|
2021-07-05 11:25:20 +01:00
|
|
|
auth?: boolean;
|
|
|
|
children: Children;
|
2021-06-18 20:07:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export const CheckAuth = (props: Props) => {
|
2021-07-05 11:25:20 +01:00
|
|
|
const operations = useContext(OperationsContext);
|
2021-06-18 20:07:26 +01:00
|
|
|
|
2021-07-05 11:25:20 +01:00
|
|
|
if (props.auth && !operations.ready()) {
|
|
|
|
return <Redirect to="/login" />;
|
|
|
|
} else if (!props.auth && operations.ready()) {
|
|
|
|
return <Redirect to="/" />;
|
|
|
|
}
|
2021-06-18 20:07:26 +01:00
|
|
|
|
2021-07-05 11:25:20 +01:00
|
|
|
return <>{props.children}</>;
|
2021-06-18 20:07:26 +01:00
|
|
|
};
|