mirror of
https://github.com/revoltchat/revite.git
synced 2025-01-07 21:24:44 -05:00
23 lines
565 B
TypeScript
23 lines
565 B
TypeScript
|
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}</>;
|
||
|
};
|