hooks.tsx67 lines · main
| 1 | import { PermissionAction } from '@supabase/shared-types/out/constants' |
| 2 | import { GenericSkeletonLoader } from 'ui-patterns' |
| 3 | import { PageContainer } from 'ui-patterns/PageContainer' |
| 4 | import { |
| 5 | PageHeader, |
| 6 | PageHeaderAside, |
| 7 | PageHeaderDescription, |
| 8 | PageHeaderMeta, |
| 9 | PageHeaderSummary, |
| 10 | PageHeaderTitle, |
| 11 | } from 'ui-patterns/PageHeader' |
| 12 | import { PageSection, PageSectionContent } from 'ui-patterns/PageSection' |
| 13 | |
| 14 | import { HooksListing } from '@/components/interfaces/Auth/Hooks/HooksListing' |
| 15 | import AuthLayout from '@/components/layouts/AuthLayout/AuthLayout' |
| 16 | import DefaultLayout from '@/components/layouts/DefaultLayout' |
| 17 | import { DocsButton } from '@/components/ui/DocsButton' |
| 18 | import NoPermission from '@/components/ui/NoPermission' |
| 19 | import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions' |
| 20 | import { DOCS_URL } from '@/lib/constants' |
| 21 | import type { NextPageWithLayout } from '@/types' |
| 22 | |
| 23 | const Hooks: NextPageWithLayout = () => { |
| 24 | const { can: canReadAuthSettings, isSuccess: isPermissionsLoaded } = useAsyncCheckPermissions( |
| 25 | PermissionAction.READ, |
| 26 | 'custom_config_gotrue' |
| 27 | ) |
| 28 | |
| 29 | if (isPermissionsLoaded && !canReadAuthSettings) { |
| 30 | return <NoPermission isFullPage resourceText="access your project's auth hooks" /> |
| 31 | } |
| 32 | |
| 33 | return ( |
| 34 | <> |
| 35 | <PageHeader size="default"> |
| 36 | <PageHeaderMeta> |
| 37 | <PageHeaderSummary> |
| 38 | <PageHeaderTitle>Auth Hooks</PageHeaderTitle> |
| 39 | <PageHeaderDescription>Customize your authentication flow</PageHeaderDescription> |
| 40 | </PageHeaderSummary> |
| 41 | <PageHeaderAside> |
| 42 | <DocsButton href={`${DOCS_URL}/guides/auth/auth-hooks`} /> |
| 43 | </PageHeaderAside> |
| 44 | </PageHeaderMeta> |
| 45 | </PageHeader> |
| 46 | <PageContainer size="default"> |
| 47 | {!isPermissionsLoaded ? ( |
| 48 | <PageSection> |
| 49 | <PageSectionContent> |
| 50 | <GenericSkeletonLoader /> |
| 51 | </PageSectionContent> |
| 52 | </PageSection> |
| 53 | ) : ( |
| 54 | <HooksListing /> |
| 55 | )} |
| 56 | </PageContainer> |
| 57 | </> |
| 58 | ) |
| 59 | } |
| 60 | |
| 61 | Hooks.getLayout = (page) => ( |
| 62 | <DefaultLayout> |
| 63 | <AuthLayout title="Auth Hooks">{page}</AuthLayout> |
| 64 | </DefaultLayout> |
| 65 | ) |
| 66 | |
| 67 | export default Hooks |