The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
chore: auth hooks entitlement (#41036)
Ignacio Dobronich9ddeb3af03ee
diff --git a/apps/studio/components/interfaces/Auth/Hooks/AddHookDropdown.tsx b/apps/studio/components/interfaces/Auth/Hooks/AddHookDropdown.tsxindex eed802a8f73..aafc243be6b 100644--- a/apps/studio/components/interfaces/Auth/Hooks/AddHookDropdown.tsx+++ b/apps/studio/components/interfaces/Auth/Hooks/AddHookDropdown.tsx@@ -1,6 +1,5 @@import { PermissionAction } from '@supabase/shared-types/out/constants'import { ChevronDown } from 'lucide-react'-import { useParams } from 'common'import { ButtonTooltip } from 'components/ui/ButtonTooltip'import { InlineLink } from 'components/ui/InlineLink'@@ -18,6 +17,8 @@ import {} from 'ui'import { HOOKS_DEFINITIONS, HOOK_DEFINITION_TITLE, Hook } from './hooks.constants'import { extractMethod, isValidHook } from './hooks.utils'+import { useCheckEntitlements } from 'hooks/misc/useCheckEntitlements'+import { useMemo } from 'react'interface AddHookDropdownProps {buttonText?: string@@ -37,25 +38,29 @@ export const AddHookDropdown = ({const { data: authConfig } = useAuthConfigQuery({ projectRef })const { can: canUpdateAuthHook } = useAsyncCheckPermissions(PermissionAction.AUTH_EXECUTE, '*')+ const { getEntitlementSetValues: getEntitledHookSet } = useCheckEntitlements('auth.hooks')+ const entitledHookSet = getEntitledHookSet()- const hooks: Hook[] = HOOKS_DEFINITIONS.map((definition) => {- return {+ const { availableHooks, nonAvailableHooks } = useMemo(() => {+ const allHooks: Hook[] = HOOKS_DEFINITIONS.map((definition) => ({...definition,enabled: authConfig?.[definition.enabledKey] || false,method: extractMethod(authConfig?.[definition.uriKey] || '',authConfig?.[definition.secretsKey] || ''),- }- })+ }))- const nonEnterpriseHookOptions = hooks.filter((h) => !isValidHook(h) && !h.enterprise)- const enterpriseHookOptions = hooks.filter((h) => !isValidHook(h) && h.enterprise)+ const availableHooks: Hook[] = allHooks.filter(+ (h) => !isValidHook(h) && entitledHookSet.includes(h.entitlementKey)+ )- const hasAccessToAdvancedHooks =- organization?.plan.id === 'team' ||- organization?.plan.id === 'enterprise' ||- organization?.plan.id === 'platform'+ const nonAvailableHooks: Hook[] = allHooks.filter(+ (h) => !isValidHook(h) && !entitledHookSet.includes(h.entitlementKey)+ )++ return { availableHooks, nonAvailableHooks }+ }, [entitledHookSet, authConfig])if (!canUpdateAuthHook) {return (@@ -80,43 +85,38 @@ export const AddHookDropdown = ({</DropdownMenuTrigger><DropdownMenuContent className="w-76" align={align}><div>- {nonEnterpriseHookOptions.map((h) => (+ {availableHooks.length === 0 && (+ <DropdownMenuLabel className="text-foreground-light">+ All available hooks have been added+ </DropdownMenuLabel>+ )}+ {availableHooks.map((h) => (<DropdownMenuItem key={h.title} onClick={() => onSelectHook(h.title)}>{h.title}</DropdownMenuItem>))}</div>+ {nonAvailableHooks.length > 0 && (+ <>+ {availableHooks.length > 0 && <DropdownMenuSeparator />}- <DropdownMenuSeparator />+ <DropdownMenuLabel className="grid gap-1 bg-surface-200">+ <p className="text-foreground-light">Team or Enterprise Plan required</p>+ <p className="text-foreground-lighter text-xs">+ The following hooks are not available on{' '}+ <InlineLink href={`/org/${organization?.slug ?? '_'}/billing`}>+ your plan+ </InlineLink>+ .+ </p>+ </DropdownMenuLabel>- {!hasAccessToAdvancedHooks && (- <DropdownMenuLabel className="grid gap-1 bg-surface-200">- <p className="text-foreground-light">Team or Enterprise Plan required</p>- <p className="text-foreground-lighter text-xs">- The following hooks are not available on{' '}- <InlineLink href={`/org/${organization?.slug ?? '_'}/billing`}>your plan</InlineLink>.- </p>- </DropdownMenuLabel>- )}- {enterpriseHookOptions.map((h) =>- hasAccessToAdvancedHooks ? (- <DropdownMenuItem- key={h.title}- disabled={!hasAccessToAdvancedHooks}- className=""- onClick={() => onSelectHook(h.title)}- >- {h.title}- </DropdownMenuItem>- ) : (- <DropdownMenuItem- key={h.title}- disabled={!hasAccessToAdvancedHooks}- onClick={() => onSelectHook(h.title)}- >- {h.title}- </DropdownMenuItem>- )+ {nonAvailableHooks.map((h) => (+ <DropdownMenuItem key={h.title} disabled={true}>+ {h.title}+ </DropdownMenuItem>+ ))}+ </>)}</DropdownMenuContent></DropdownMenu>diff --git a/apps/studio/components/interfaces/Auth/Hooks/hooks.constants.ts b/apps/studio/components/interfaces/Auth/Hooks/hooks.constants.tsindex eb5234874aa..28037f8adb5 100644--- a/apps/studio/components/interfaces/Auth/Hooks/hooks.constants.ts+++ b/apps/studio/components/interfaces/Auth/Hooks/hooks.constants.ts@@ -3,20 +3,20 @@ export const HOOKS_DEFINITIONS = [id: 'send-sms',title: 'Send SMS hook',subtitle: 'Will be called by Supabase Auth each time an SMS message needs to be sent.',+ entitlementKey: 'HOOK_SEND_SMS',enabledKey: 'HOOK_SEND_SMS_ENABLED',uriKey: 'HOOK_SEND_SMS_URI',secretsKey: 'HOOK_SEND_SMS_SECRETS',- enterprise: false,docSlug: 'send-sms-hook',},{id: 'send-email',title: 'Send Email hook',subtitle: 'Will be called by Supabase Auth each time an email message needs to be sent.',+ entitlementKey: 'HOOK_SEND_EMAIL',enabledKey: 'HOOK_SEND_EMAIL_ENABLED',uriKey: 'HOOK_SEND_EMAIL_URI',secretsKey: 'HOOK_SEND_EMAIL_SECRETS',- enterprise: false,docSlug: 'send-email-hook',},{@@ -24,10 +24,10 @@ export const HOOKS_DEFINITIONS = [title: 'Customize Access Token (JWT) Claims hook',subtitle:'Will be called by Supabase Auth each time a new JWT is created. It should return the claims you wish to be present in the JWT.',+ entitlementKey: 'HOOK_CUSTOM_ACCESS_TOKEN',enabledKey: 'HOOK_CUSTOM_ACCESS_TOKEN_ENABLED',uriKey: 'HOOK_CUSTOM_ACCESS_TOKEN_URI',secretsKey: 'HOOK_CUSTOM_ACCESS_TOKEN_SECRETS',- enterprise: false,docSlug: 'custom-access-token-hook',},{@@ -35,10 +35,10 @@ export const HOOKS_DEFINITIONS = [title: 'MFA Verification Attempt hook',subtitle:'Will be called by Supabase Auth each time a user tries to verify an MFA factor. Return a decision on whether to reject the attempt and future ones, or to allow the user to keep trying.',+ entitlementKey: 'HOOK_MFA_VERIFICATION_ATTEMPT',enabledKey: 'HOOK_MFA_VERIFICATION_ATTEMPT_ENABLED',uriKey: 'HOOK_MFA_VERIFICATION_ATTEMPT_URI',secretsKey: 'HOOK_MFA_VERIFICATION_ATTEMPT_SECRETS',- enterprise: true,docSlug: 'mfa-verification-hook',},{@@ -46,10 +46,10 @@ export const HOOKS_DEFINITIONS = [title: 'Password Verification Attempt hook',subtitle:'Will be called by Supabase Auth each time a user tries to sign in with a password. Return a decision whether to allow the user to reject the attempt, or to allow the user to keep trying.',+ entitlementKey: 'HOOK_PASSWORD_VERIFICATION_ATTEMPT',enabledKey: 'HOOK_PASSWORD_VERIFICATION_ATTEMPT_ENABLED',uriKey: 'HOOK_PASSWORD_VERIFICATION_ATTEMPT_URI',secretsKey: 'HOOK_PASSWORD_VERIFICATION_ATTEMPT_SECRETS',- enterprise: true,docSlug: 'password-verification-hook',},{@@ -57,10 +57,10 @@ export const HOOKS_DEFINITIONS = [title: 'Before User Created hook',subtitle:'Will be called by Supabase Auth before creating a new user. Returning an error will prevent the user from being created.',+ entitlementKey: 'HOOK_BEFORE_USER_CREATED',enabledKey: 'HOOK_BEFORE_USER_CREATED_ENABLED',uriKey: 'HOOK_BEFORE_USER_CREATED_URI',secretsKey: 'HOOK_BEFORE_USER_CREATED_SECRETS',- enterprise: false,docSlug: 'before-user-created-hook',},] as const@@ -71,6 +71,7 @@ export interface Hook {id: stringtitle: HOOK_DEFINITION_TITLEsubtitle: string+ entitlementKey: stringenabled: booleanenabledKey: stringuriKey: string@@ -79,5 +80,4 @@ export interface Hook {method:| { type: 'postgres'; schema: string; functionName: string }| { type: 'https'; url: string; secret: string }- enterprise: boolean}