oops nevermind LOL
This commit is contained in:
@@ -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) {
|
|
||||||
if (accessRules.mustBeRecipinAdmin && !(user.isadmin)) {
|
|
||||||
setView(
|
|
||||||
<AccessForbidden>
|
|
||||||
<>
|
|
||||||
<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 (
|
||||||
return view;
|
<Page>
|
||||||
|
{ children }
|
||||||
|
</Page>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Protect;
|
export default Protect;
|
||||||
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user