mirror of
https://github.com/revoltchat/revite.git
synced 2025-01-07 21:24:44 -05:00
29 lines
746 B
TypeScript
29 lines
746 B
TypeScript
import { Redirect } from "react-router-dom";
|
|
|
|
import { useApplicationState } from "../../mobx/State";
|
|
|
|
import { Children } from "../../types/Preact";
|
|
import { useClient } from "./RevoltClient";
|
|
|
|
interface Props {
|
|
auth?: boolean;
|
|
blockRender?: boolean;
|
|
|
|
children: Children;
|
|
}
|
|
|
|
export const CheckAuth = (props: Props) => {
|
|
const auth = useApplicationState().auth;
|
|
const client = useClient();
|
|
const ready = auth.isLoggedIn() && !!client?.user;
|
|
|
|
if (props.auth && !ready) {
|
|
if (props.blockRender) return null;
|
|
return <Redirect to="/login" />;
|
|
} else if (!props.auth && ready) {
|
|
if (props.blockRender) return null;
|
|
return <Redirect to="/" />;
|
|
}
|
|
|
|
return <>{props.children}</>;
|
|
};
|