webapp/src/components/_shared/ShowIfAuthenticated.tsx

21 lines
434 B
TypeScript
Raw Normal View History

2023-02-17 09:21:02 +00:00
import type { JSX } from 'solid-js'
2023-02-17 09:21:02 +00:00
import { Show } from 'solid-js'
import { useSession } from '~/context/session'
2023-02-17 09:21:02 +00:00
type ShowIfAuthenticatedProps = {
children: JSX.Element
fallback?: JSX.Element
}
export const ShowIfAuthenticated = (props: ShowIfAuthenticatedProps) => {
2024-06-24 17:50:27 +00:00
const { session } = useSession()
2023-02-17 09:21:02 +00:00
return (
2024-06-24 17:50:27 +00:00
<Show when={session()?.access_token} fallback={props.fallback}>
2023-02-17 09:21:02 +00:00
{props.children}
</Show>
)
}