oops nevermind LOL

This commit is contained in:
Mikayla Dobson
2023-02-18 11:05:48 -06:00
parent a7f3fd6e10
commit 1d4763333b
2 changed files with 24 additions and 26 deletions

View File

@@ -7,41 +7,39 @@ import API from "./API";
import { ProtectPortal } from "./types"; import { ProtectPortal } from "./types";
const Protect: ProtectPortal = ({ children, redirect = '', accessRules = null }) => { const Protect: ProtectPortal = ({ children, redirect = '', accessRules = null }) => {
const [view, setView] = useState(<Page><h1>Loading...</h1></Page>);
const { user, token } = useAuthContext(); const { user, token } = useAuthContext();
const navigate = useNavigate(); const navigate = useNavigate();
useEffect(() => { if (!user || !token) {
if (!user || !token) { return (
setView( <AccessForbidden>
<>
<h2>Hi there! You don't look too familiar.</h2>
<p>To view the content on this page, please log in below:</p>
<Button onClick={() => navigate(redirect ? `/login?redirect=${redirect}` : '/login')}>Log In</Button>
</>
</AccessForbidden>
)
}
if (accessRules !== null) {
if (accessRules.mustBeRecipinAdmin && !(user?.isadmin)) {
return (
<AccessForbidden> <AccessForbidden>
<> <>
<h2>Hi there! You don't look too familiar.</h2> <h2>This page requires administrator access.</h2>
<p>To view the content on this page, please log in below:</p> <p>If you believe you are receiving this message in error, please contact Recipin support.</p>
<Button onClick={() => navigate(redirect ? `/login?redirect=${redirect}` : '/login')}>Log In</Button>
</> </>
</AccessForbidden> </AccessForbidden>
) )
return;
} }
}
if (accessRules !== null) { return (
if (accessRules.mustBeRecipinAdmin && !(user.isadmin)) { <Page>
setView( { children }
<AccessForbidden> </Page>
<> )
<h2>This page requires administrator access.</h2>
<p>If you believe you are receiving this message in error, please contact Recipin support.</p>
</>
</AccessForbidden>
)
}
}
}, [user, token])
return view;
} }
export default Protect; export default Protect;

View File

@@ -23,7 +23,7 @@ export interface AccessRules {
export interface ProtectParams extends PortalBase { export interface ProtectParams extends PortalBase {
redirect?: string redirect?: string
accessRules?: AccessRules | null accessRules?: Partial<AccessRules> | null
} }
interface UserCardProps extends PortalBase { interface UserCardProps extends PortalBase {