2023-02-27 22:01:48 +00:00
|
|
|
import { component$, Slot } from '@builder.io/qwik'
|
|
|
|
import { loader$ } from '@builder.io/qwik-city'
|
|
|
|
import * as access from 'wildebeest/backend/src/access'
|
|
|
|
import { checkAuth } from '~/utils/checkAuth'
|
|
|
|
|
|
|
|
type AccessLoaderData = {
|
|
|
|
loginUrl: string
|
|
|
|
isAuthorized: boolean
|
|
|
|
}
|
|
|
|
|
2023-03-02 09:33:25 +00:00
|
|
|
export const accessLoader = loader$<Promise<AccessLoaderData>>(async ({ platform, request }) => {
|
2023-02-27 22:01:48 +00:00
|
|
|
const isAuthorized = await checkAuth(request, platform)
|
|
|
|
|
|
|
|
return {
|
|
|
|
isAuthorized,
|
|
|
|
loginUrl: access.generateLoginURL({
|
|
|
|
redirectURL: request.url,
|
|
|
|
domain: platform.ACCESS_AUTH_DOMAIN,
|
|
|
|
aud: platform.ACCESS_AUD,
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
export default component$(() => {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Slot />
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
})
|