mirror of
https://github.com/stoatchat/for-legacy-web.git
synced 2026-03-08 01:45:28 +00:00
Add client context.
This commit is contained in:
22
src/context/revoltjs/CheckAuth.tsx
Normal file
22
src/context/revoltjs/CheckAuth.tsx
Normal 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}</>;
|
||||
};
|
||||
Reference in New Issue
Block a user