mirror of
https://github.com/revoltchat/revite.git
synced 2025-01-04 11:44:44 -05:00
23 lines
573 B
TypeScript
23 lines
573 B
TypeScript
import { Redirect } from "react-router-dom";
|
|
|
|
import { useContext } from "preact/hooks";
|
|
|
|
import { Children } from "../../types/Preact";
|
|
import { OperationsContext } from "./RevoltClient";
|
|
|
|
interface Props {
|
|
auth?: boolean;
|
|
children: Children;
|
|
}
|
|
|
|
export const CheckAuth = (props: Props) => {
|
|
const operations = useContext(OperationsContext);
|
|
|
|
if (props.auth && !operations.ready()) {
|
|
return <Redirect to="/login" />;
|
|
} else if (!props.auth && operations.ready()) {
|
|
return <Redirect to="/" />;
|
|
}
|
|
|
|
return <>{props.children}</>;
|
|
};
|