Add client context.

This commit is contained in:
Paul
2021-06-18 20:07:26 +01:00
parent e7d1ada13d
commit aa81ebb298
12 changed files with 260 additions and 33 deletions

View File

@@ -0,0 +1,22 @@
import { ReactNode } from "react";
import { useContext } from "preact/hooks";
import { Redirect } from "react-router-dom";
import { AppContext } from "./RevoltClient";
interface Props {
auth?: boolean;
children: ReactNode | ReactNode[];
}
export const CheckAuth = (props: Props) => {
const { operations } = useContext(AppContext);
if (props.auth && !operations.ready()) {
return <Redirect to="/login" />;
} else if (!props.auth && operations.ready()) {
return <Redirect to="/" />;
}
return <>{props.children}</>;
};