
* feed period select * fix, unused code removed * Fix styles * Fix styles * Fix styles --------- Co-authored-by: Igor Lobanov <igor.lobanov@onetwotrip.com> Co-authored-by: ilya-bkv <i.yablokov@ccmp.me>
39 lines
997 B
TypeScript
39 lines
997 B
TypeScript
import { createEffect, JSX, Show } from 'solid-js'
|
|
|
|
import { useSession } from '../../context/session'
|
|
import { RootSearchParams } from '../../pages/types'
|
|
import { useRouter } from '../../stores/router'
|
|
import { hideModal } from '../../stores/ui'
|
|
import { AuthModalSearchParams } from '../Nav/AuthModal/types'
|
|
|
|
type Props = {
|
|
children: JSX.Element
|
|
disabled?: boolean
|
|
}
|
|
|
|
export const AuthGuard = (props: Props) => {
|
|
const { isAuthenticated, isSessionLoaded } = useSession()
|
|
const { changeSearchParams } = useRouter<RootSearchParams & AuthModalSearchParams>()
|
|
|
|
createEffect(() => {
|
|
if (props.disabled) {
|
|
return
|
|
}
|
|
if (isSessionLoaded()) {
|
|
if (isAuthenticated()) {
|
|
hideModal()
|
|
} else {
|
|
changeSearchParams(
|
|
{
|
|
source: 'authguard',
|
|
modal: 'auth',
|
|
},
|
|
true,
|
|
)
|
|
}
|
|
}
|
|
})
|
|
|
|
return <Show when={(isSessionLoaded() && isAuthenticated()) || props.disabled}>{props.children}</Show>
|
|
}
|