import type { JSX } from 'preact' ; import { h } from 'preact' ; import { useContext } from 'preact/hooks' ; import { useTitleTemplate } from 'hoofd/preact' ; import Spinner from './Spinner' ; import Redirect from './Redirect' ; import UserContext from '../UserContext' ; import { Endpoints } from '../../constants' ; type AuthBoundaryProps = { children : JSX . Element ; staff ? : boolean ; } & Record < string , unknown > ; export default function AuthBoundary ( { children , staff } ) { const user = useContext ( UserContext ) ; const path = typeof location !== 'undefined' ? location . pathname : '' ; if ( user === void 0 ) { useTitleTemplate ( 'Powercord' ) ; return ( < main > < Spinner /> < /main>); } if ( ! user ) { return ( < main > < h1 > You must be authenticated to see this < /h1> < p > { } < a href = { `${ Endpoints . LOGIN }?redirect=${ path }` } native > Login < /a> < /p> < /main>); } if ( staff && ! user ?. badges ?. staff ) { return < Redirect to = '/' / > ; } return children ; }