:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(workflows): add a skill for setting up supabase auth emails (#124976)
Luke Beltondaf874738f96
diff --git a/products/messaging/mcp/tools.yaml b/products/messaging/mcp/tools.yamlindex e6af4c43aa39..27352070f423 100644--- a/products/messaging/mcp/tools.yaml+++ b/products/messaging/mcp/tools.yaml@@ -135,10 +135,11 @@ tools:idempotent: truetitle: Update the Supabase auth email settingsdescription: >- Update how the project sends a Supabase project's auth emails. Send only the fields to change. To get- templates to map, call supabase-auth-emails-starter-templates-create or use the email template tools. Ask- the user for the hook secret. Never invent one. Sending starts when the user turns on the Send Email hook in- Supabase, so map the core emails before telling them to.+ Update how the project sends a Supabase project's auth emails. Send only the fields to change, but templates+ replaces the whole mapping, so include every type to keep. To get templates to map, call+ supabase-auth-emails-starter-templates-create or use the email template tools. Ask the user for the hook+ secret. Never invent one. Map the core emails before the user turns on the hook in Supabase. Load the+ setting-up-supabase-auth-emails skill before you set up or change the connection.feature_flag: workflows-supabase-auth-emailsresponse:exclude:@@ -157,7 +158,8 @@ tools:description: >Create and map an email template for each core Supabase auth email that has no usable template yet. A repeatcall skips types that still have one. Needs a verified email sender on the project. Edit the templates- afterwards with the email template tools.+ afterwards with the email template tools. Load the setting-up-supabase-auth-emails skill before you set up+ the connection.feature_flag: workflows-supabase-auth-emailsresponse:exclude:diff --git a/products/workflows/frontend/SupabaseAuthEmails/supabaseAuthEmailsLogic.test.ts b/products/workflows/frontend/SupabaseAuthEmails/supabaseAuthEmailsLogic.test.tsnew file mode 100644index 000000000000..1af44f7945cc--- /dev/null+++ b/products/workflows/frontend/SupabaseAuthEmails/supabaseAuthEmailsLogic.test.ts@@ -0,0 +1,47 @@+import { router } from 'kea-router'+import { expectLogic } from 'kea-test-utils'++import { urls } from 'scenes/urls'++import { useMocks } from '~/mocks/jest'+import { initKeaTests } from '~/test/init'++import { supabaseAuthEmailsLogic } from './supabaseAuthEmailsLogic'++describe('supabaseAuthEmailsLogic', () => {+ beforeEach(() => {+ useMocks({+ get: {+ '/api/projects/:team_id/messaging_supabase_auth_emails/settings/': {+ supabase_url: '',+ has_hook_secret: false,+ hook_url: 'https://example.com/hook',+ templates: {},+ email_types: [],+ },+ '/api/projects/:team_id/messaging_templates/': { results: [], next: null },+ },+ })+ initKeaTests()+ })++ it.each([urls.workflows('channels'), urls.broadcasts('channels'), urls.transactional('channels')])(+ 'opens the setup from a link to %s and drops the param on close',+ async (channelsUrl) => {+ router.actions.push(channelsUrl, { setup: 'supabase', other: 'kept' })+ const logic = supabaseAuthEmailsLogic()+ logic.mount()++ await expectLogic(logic).toDispatchActions(['openSetup']).toMatchValues({ isSetupOpen: true })++ logic.actions.closeSetup()++ expect(logic.values.isSetupOpen).toBe(false)+ expect(router.values.searchParams).toEqual({ other: 'kept' })++ logic.actions.openSetup()++ expect(router.values.searchParams).toEqual({ other: 'kept', setup: 'supabase' })+ }+ )+})diff --git a/products/workflows/frontend/SupabaseAuthEmails/supabaseAuthEmailsLogic.ts b/products/workflows/frontend/SupabaseAuthEmails/supabaseAuthEmailsLogic.tsindex 4eea675c7549..6140c15f3db0 100644--- a/products/workflows/frontend/SupabaseAuthEmails/supabaseAuthEmailsLogic.ts+++ b/products/workflows/frontend/SupabaseAuthEmails/supabaseAuthEmailsLogic.ts@@ -1,11 +1,13 @@import { MakeLogicType, actions, afterMount, connect, kea, listeners, path, reducers, selectors } from 'kea'import { loaders } from 'kea-loaders'+import { actionToUrl, router, urlToAction } from 'kea-router'import { lemonToast } from '@posthog/lemon-ui'import { ApiError } from 'lib/api'import { listAllPages } from 'scenes/settings/environment/cloudEnvironmentsLogic'import { teamLogic } from 'scenes/teamLogic'+import { urls } from 'scenes/urls'import {messagingSupabaseAuthEmailsSettingsDestroy,@@ -23,6 +25,10 @@ import type {export type SupabaseAuthEmailsStatus = 'connected' | 'incomplete' | 'not-set-up'+// `?setup=supabase` on a Channels tab opens the setup modal, so the agent skill and docs can link straight to it.+const SETUP_PARAM = 'setup'+const SETUP_PARAM_VALUE = 'supabase'+function errorMessage(error: unknown, fallback: string): string {return error instanceof ApiError && error.detail ? error.detail : fallback}@@ -357,6 +363,33 @@ export const supabaseAuthEmailsLogic = kea<supabaseAuthEmailsLogicType>([}},})),+ actionToUrl(() => ({+ // A history entry, so the back button closes the setup.+ openSetup: () => [+ router.values.location.pathname,+ { ...router.values.searchParams, [SETUP_PARAM]: SETUP_PARAM_VALUE },+ router.values.hashParams,+ ],+ closeSetup: () => {+ const { [SETUP_PARAM]: _, ...searchParams } = router.values.searchParams+ return [router.values.location.pathname, searchParams, router.values.hashParams, { replace: true }]+ },+ })),+ urlToAction(({ actions, values }) => {+ const syncSetupWithUrl = (_: Record<string, string | undefined>, searchParams: Record<string, any>): void => {+ const wantsSetup = searchParams[SETUP_PARAM] === SETUP_PARAM_VALUE+ if (wantsSetup && !values.isSetupOpen) {+ actions.openSetup()+ } else if (!wantsSetup && values.isSetupOpen) {+ actions.closeSetup()+ }+ }+ return {+ [urls.workflows('channels')]: syncSetupWithUrl,+ [urls.broadcasts('channels')]: syncSetupWithUrl,+ [urls.transactional('channels')]: syncSetupWithUrl,+ }+ }),afterMount(({ actions }) => {actions.loadSettings()}),diff --git a/products/workflows/skills/setting-up-supabase-auth-emails/SKILL.md b/products/workflows/skills/setting-up-supabase-auth-emails/SKILL.mdnew file mode 100644index 000000000000..ee0b8cd1da00--- /dev/null+++ b/products/workflows/skills/setting-up-supabase-auth-emails/SKILL.md@@ -0,0 +1,53 @@+---+name: setting-up-supabase-auth-emails+description: 'Connect a Supabase project so its auth emails send through PostHog email templates via the Supabase Send Email Hook, in an order that never breaks a sign-up. Use when asked to set up, connect, test, or fix Supabase auth emails, Supabase email templates, or the Supabase Send Email Hook, or when Supabase shows "email rate limit exceeded" or an auth email error.'+---++# Setting up Supabase auth emails++Supabase calls PostHog's Send Email Hook for each auth email. The user does the Supabase steps by hand, so tell them exactly what to click, and keep the order below.++If the Supabase MCP server is connected, use it to read the project URL (step 4) and the logs (when a hook call fails). It has no tools for Auth settings. Leave the hook and the rate limit to the user even if you have other Supabase access, because those settings send every sign-up email.++The tools are behind a beta flag. If `supabase-auth-emails-settings-get` isn't available, tell the user the feature isn't enabled for their project yet and stop.++## The setup++1. **Read the current state.** Call `supabase-auth-emails-settings-get`. Keep the `hook_url`, the `email_types` list and the current `templates` mapping. If the project is already set up, change only what the user asked for.+2. **Ask the user's choices in one go.** Ask these together, before any change. Use the client's multiple-choice question tool if it has one. Skip any question the state from step 1 already answers.+ - **Project:** with no Supabase MCP, ask for the Supabase dashboard link of the project (`supabase.com/dashboard/project/<project-ref>`).+ - **Templates:** create PostHog's starter templates, or use templates they already have.+ - **Hook secret:** paste it into the chat, or enter it in PostHog themselves.+3. **Check the email sender.** The templates need an email channel with a verified sending domain. Follow the setup check in the `building-workflows` skill's onboarding reference.+4. **Save the project URL.** With the Supabase MCP, call `get_project_url`. Otherwise it is `https://<project-ref>.supabase.co`. For a self-hosted project or a custom domain, ask the user for the URL their app uses to reach Supabase Auth. Save it with `supabase-auth-emails-settings-update`.+5. **Have the user create the hook in Supabase, switched off.** While the hook is on, any hook failure fails the user's sign-up or password reset. Give them the `hook_url` and these steps:+ - Open **Authentication** > **Hooks**, add a **Send Email** hook, and choose **HTTPS**.+ - Paste the hook URL as the endpoint.+ - Click **Generate secret** and copy the whole value.+ - Leave **Enable Send Email hook** off, and save.+6. **Save the hook secret.** Never invent a hook secret. If a secret is already stored, leave `hook_secret` out to keep it, and ask before you replace it. Never send it blank, because a blank value clears it.+ - **In the chat:** save it with `supabase-auth-emails-settings-update`. Don't repeat it back in your reply.+ - **In PostHog:** give the user a link to `/workflows/channels?setup=supabase` in their PostHog app. It opens the Supabase setup. They paste the secret and click **Save connection**. Then call `supabase-auth-emails-settings-get` and confirm `has_hook_secret` is true.+7. **Map the templates**, as the user chose in step 2:+ - **Starter templates.** Call `supabase-auth-emails-starter-templates-create`. It creates and maps a template for each email type with `has_starter_template` that has no usable one yet. If it fails for want of a verified sender, go back to step 3. To change a template's copy or styling, use the `designing-email-templates` skill.+ - **Existing templates.** List them with `workflows-list-email-templates`, keep the ones that are transactional and marked sensitive, and ask the user which one sends each email. A template that is neither can't be mapped yet. Ask before you make one transactional, because that can't be undone. Send the mapping with `supabase-auth-emails-settings-update`. Build `templates` from the step 1 mapping with your changes merged in, because the field replaces the whole mapping. Ask before you unmap a template that already sends.+8. **Check before the hook goes live.** In the response of your last call, confirm `supabase_url` is set, `has_hook_secret` is true, and every core email type in the `email_types` list from step 1 has a template. The write responses leave that list out. Core types are the ones that don't end in `_notification`. A core type with no template fails the user's action. A notification with no template is skipped.+9. **Have the user turn the hook on.** In Supabase, edit the Send Email hook, switch on **Enable Send Email hook**, and save. PostHog can't see whether the hook is on, so the **Connected** status on the Supabase card only means the connection is saved.+10. **Have the user raise Supabase's email rate limit.** Supabase checks its own hourly email limit before it calls PostHog. The built-in mailer allows 2 per hour. Once the hook sends the emails, the user can raise the limit under **Authentication** > **Rate Limits**. Ask them to check the value there.+11. **Test it.** Ask the user to invite a user (**Authentication** > **Users** > **Add user** > **Send invitation**) or request a password reset, to an address they can read. The email should arrive from the mapped template.++Report done only after the user confirms a test email arrived. Name any email type you left without a template.++To disconnect, the user turns the hook off in Supabase first, then clicks **Disconnect** in the PostHog setup window. In the other order, every auth email fails in between.++## When a hook call fails++The user sees these in Supabase, in the app's error or under **Logs** > **Auth**. With the Supabase MCP, find the failed call yourself with its `query_logs` tool before you ask the user. That tool reads Supabase's logs. PostHog's `query-logs` tool can't see them.++| What Supabase shows | Cause | Fix |+| ---------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------- |+| "email rate limit exceeded" | Supabase's own hourly limit. PostHog never got the call. | Raise the limit (step 10). |+| Supabase's generic hook error, with a 401 from the hook | The hook secret doesn't match. | Have the user copy the full secret again and save it with `supabase-auth-emails-settings-update`. |+| "No PostHog template is set for the ... email." | A core email type has no template. | Map one (step 7). |+| "We couldn't send your email. Try again in a few minutes." | No project URL saved, a mapped template that is deleted or no longer transactional and sensitive, no verified sender, the email quota, or a slow send. | Check the settings and each mapped template. If they are fine, retry. |+| Links in the email go to the wrong place | The project URL is wrong. | Save the right URL. |diff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.jsonindex a8d6c834ff46..4c402fc4639c 100644--- a/services/mcp/schema/generated-tool-definitions.json+++ b/services/mcp/schema/generated-tool-definitions.json@@ -14383,7 +14383,7 @@"feature_flag": "workflows-supabase-auth-emails"},"supabase-auth-emails-settings-update": {- "description": "Update how the project sends a Supabase project's auth emails. Send only the fields to change. To get templates to map, call supabase-auth-emails-starter-templates-create or use the email template tools. Ask the user for the hook secret. Never invent one. Sending starts when the user turns on the Send Email hook in Supabase, so map the core emails before telling them to.",+ "description": "Update how the project sends a Supabase project's auth emails. Send only the fields to change, but templates replaces the whole mapping, so include every type to keep. To get templates to map, call supabase-auth-emails-starter-templates-create or use the email template tools. Ask the user for the hook secret. Never invent one. Map the core emails before the user turns on the hook in Supabase. Load the setting-up-supabase-auth-emails skill before you set up or change the connection.","category": "Messaging","feature": "messaging","summary": "Update the Supabase auth email settings",@@ -14399,7 +14399,7 @@"feature_flag": "workflows-supabase-auth-emails"},"supabase-auth-emails-starter-templates-create": {- "description": "Create and map an email template for each core Supabase auth email that has no usable template yet. A repeat call skips types that still have one. Needs a verified email sender on the project. Edit the templates afterwards with the email template tools.",+ "description": "Create and map an email template for each core Supabase auth email that has no usable template yet. A repeat call skips types that still have one. Needs a verified email sender on the project. Edit the templates afterwards with the email template tools. Load the setting-up-supabase-auth-emails skill before you set up the connection.","category": "Messaging","feature": "messaging","summary": "Create starter templates for the Supabase auth emails",diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.jsonindex 8948c8445204..0e09f763ef92 100644--- a/services/mcp/schema/tool-definitions-all.json+++ b/services/mcp/schema/tool-definitions-all.json@@ -15086,7 +15086,7 @@"feature_flag": "workflows-supabase-auth-emails"},"supabase-auth-emails-settings-update": {- "description": "Update how the project sends a Supabase project's auth emails. Send only the fields to change. To get templates to map, call supabase-auth-emails-starter-templates-create or use the email template tools. Ask the user for the hook secret. Never invent one. Sending starts when the user turns on the Send Email hook in Supabase, so map the core emails before telling them to.",+ "description": "Update how the project sends a Supabase project's auth emails. Send only the fields to change, but templates replaces the whole mapping, so include every type to keep. To get templates to map, call supabase-auth-emails-starter-templates-create or use the email template tools. Ask the user for the hook secret. Never invent one. Map the core emails before the user turns on the hook in Supabase. Load the setting-up-supabase-auth-emails skill before you set up or change the connection.","category": "Messaging","feature": "messaging","summary": "Update the Supabase auth email settings",@@ -15102,7 +15102,7 @@"feature_flag": "workflows-supabase-auth-emails"},"supabase-auth-emails-starter-templates-create": {- "description": "Create and map an email template for each core Supabase auth email that has no usable template yet. A repeat call skips types that still have one. Needs a verified email sender on the project. Edit the templates afterwards with the email template tools.",+ "description": "Create and map an email template for each core Supabase auth email that has no usable template yet. A repeat call skips types that still have one. Needs a verified email sender on the project. Edit the templates afterwards with the email template tools. Load the setting-up-supabase-auth-emails skill before you set up the connection.","category": "Messaging","feature": "messaging","summary": "Create starter templates for the Supabase auth emails",