Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

docs(auth): improve auth hooks (#28936)

Florian Lefebvre508420a9c494
diff --git a/apps/docs/content/guides/auth/auth-hooks.mdx b/apps/docs/content/guides/auth/auth-hooks.mdx
index 41aee9b1e93..f8ac3537013 100644
--- a/apps/docs/content/guides/auth/auth-hooks.mdx
+++ b/apps/docs/content/guides/auth/auth-hooks.mdx
@@ -96,16 +96,16 @@ HTTP Hooks in Supabase follow the [Standard Webhooks Specification](https://www.
When the request is made to the HTTP hook, you should use the [Standard Webhooks libraries](https://github.com/standard-webhooks/standard-webhooks/tree/main/libraries) to verify these headers.
-When a HTTP hook is created, the secret generated should be of the following format: `v1,whsec_<standard-base64-secret>`:
+When a HTTP hook is created, the secret generated should be of the `v1,whsec_<base64-secret>` format:
- `v1` denotes the version of the hook
- `whsec_` signifies that the secret is symmetric
-- `<standard-base64-secret>` implies a Standard Base64 encoded secret which can contain the characters `+`, `/` and `=`
+- `<base64-secret>` implies a Standard Base64 encoded secret which can contain the characters `+`, `/` and `=`
The secret is used to verify the payload received in your hook. Create an entry in your `.env.local` file to store the `<standard-base64-secret>` portion of the secret for each hook that you have. For example:
-```bash
-HOOK_SECRETS=<standard-base64-secret>
+```ini
+SEND_SMS_HOOK_SECRETS=v1,whsec_<base64-secret>
```
There field is expressed in plural rather than singular as there are plans to allow for asymmetric signing and multiple hook secrets for ease of secret rotation. For instance: `<standard-base-64-secret>|<another-standard-base-64-secret>`.
@@ -117,7 +117,7 @@ import { Webhook } from 'https://esm.sh/[email protected]'
Deno.serve(async (req) => {
const payload = await req.text()
- const hookSecret = Deno.env.get('HOOK_SECRETS')
+ const hookSecret = Deno.env.get('SEND_SMS_HOOK_SECRETS').replace('v1,whsec_', '')
// Extract headers and security specific fields
const headers = Object.fromEntries(req.headers)
const wh = new Webhook(hookSecret)
@@ -229,19 +229,25 @@ You can visit `SQL Editor > Templates` for hook templates.
</TabPanel>
<TabPanel id="http" label="HTTP">
Modify the `auth.hook.<hook_name>` field and set `uri` to a valid HTTP URI. For example, the `send_sms` hook would take the following fields:
-```
+
+```toml
[auth.hook.send_sms]
enabled = true
uri = "http://host.docker.internal:54321/functions/v1/send_sms"
-secrets = "env(SEND_SMS_HOOK_SECRET)"
+# Comma separated list of secrets
+secrets = "env(SEND_SMS_HOOK_SECRETS)"
```
-`host.docker.internal` is a special DNS name used in Docker to allow a container to access the host machine's network. This allows the Auth container to reach the Functions container
+<Admonition type="info">
+
+`host.docker.internal` is a special DNS name used in Docker to allow a container to access the host machine's network. This allows the Auth container to reach your HTTP function, no matter if it's a Supabase Edge Function or a custom endpoint.
+
+</Admonition>
Fill in the Hook Secret in `supabase/functions/.env`
-```bash
-SEND_SMS_HOOK_SECRET='v1,whsec_<base64_standard_secret>'
+```ini
+SEND_SMS_HOOK_SECRETS='v1,whsec_<base64-secret>'
```
Start the function locally:
diff --git a/apps/docs/content/guides/auth/auth-hooks/custom-access-token-hook.mdx b/apps/docs/content/guides/auth/auth-hooks/custom-access-token-hook.mdx
index a689d23dd79..aff8766f938 100644
--- a/apps/docs/content/guides/auth/auth-hooks/custom-access-token-hook.mdx
+++ b/apps/docs/content/guides/auth/auth-hooks/custom-access-token-hook.mdx
@@ -431,7 +431,7 @@ import * as base64 from 'https://denopkg.com/chiefbiiko/base64/mod.ts'
Deno.serve(async (req) => {
const payload = await req.text()
- const base64_secret = Deno.env.get('AUTH_CUSTOM_ACCESS_TOKEN_SECRET')
+ const base64_secret = Deno.env.get('CUSTOM_ACCESS_TOKEN_SECRET').replace('v1,whsec_', '')
const headers = Object.fromEntries(req.headers)
const wh = new Webhook(base64_secret)
try {
@@ -477,7 +477,7 @@ import * as base64 from 'https://denopkg.com/chiefbiiko/base64/mod.ts'
Deno.serve(async (req) => {
const payload = await req.text()
- const base64_secret = Deno.env.get('AUTH_CUSTOM_ACCESS_TOKEN_SECRET')
+ const base64_secret = Deno.env.get('CUSTOM_ACCESS_TOKEN_SECRET').replace('v1,whsec_', '')
const headers = Object.fromEntries(req.headers)
const wh = new Webhook(base64_secret)
try {
diff --git a/apps/docs/content/guides/auth/auth-hooks/send-email-hook.mdx b/apps/docs/content/guides/auth/auth-hooks/send-email-hook.mdx
index 89a22ba9292..f7a08c4934d 100644
--- a/apps/docs/content/guides/auth/auth-hooks/send-email-hook.mdx
+++ b/apps/docs/content/guides/auth/auth-hooks/send-email-hook.mdx
@@ -282,7 +282,7 @@ Email sending depends on two settings: Email Provider and Auth Hook status.
},
"email_action_type": {
"type": "string",
- "enum": ["signup", "login", "reset_password"]
+ "enum": ["signup", "invite", "magiclink", "recovery", "email_change", "email"]
},
"site_url": {
"type": "string",
@@ -472,14 +472,14 @@ If you want to send emails through the Supabase Resend integration, which uses R
Create a `.env` file with the following environment variables:
-```bash
-RESEND_API_KEY=your_resend_api_key
-SEND_EMAIL_HOOK_SECRET=<base64_secret>
+```ini
+RESEND_API_KEY="your_resend_api_key"
+SEND_EMAIL_HOOK_SECRET="v1,whsec_<base64_secret>"
```
<Admonition type="note">
-You can generate the secret in the [Auth Hooks](/dashboard/project/_/auth/hooks) section of the Supabase dashboard. Make sure to remove the `v1,whsec_` prefix!
+You can generate the secret in the [Auth Hooks](/dashboard/project/_/auth/hooks) section of the Supabase dashboard.
</Admonition>
@@ -502,7 +502,7 @@ import { Webhook } from "https://esm.sh/[email protected]";
import { Resend } from "npm:resend";
const resend = new Resend(Deno.env.get("RESEND_API_KEY") as string);
-const hookSecret = Deno.env.get("SEND_EMAIL_HOOK_SECRET") as string;
+const hookSecret = (Deno.env.get("SEND_EMAIL_HOOK_SECRET") as string).replace("v1,whsec_", "");
Deno.serve(async (req) => {
if (req.method !== "POST") {
@@ -569,7 +569,7 @@ supabase functions deploy send-email --no-verify-jwt
</TabPanel>
<TabPanel id="http-internationalization-for-emails" label="Add Internationalization for Email Templates">
-Your company is expanding to France and Spain. As part of expansion efforts, the company would like to deliver internationalized email templates to best support local users in their native language. Ensure that you have configured `POSTMARK_SERVER_TOKEN` and `AUTH_SEND_EMAIL_HOOK_SECRET` in your `.env` file.
+Your company is expanding to France and Spain. As part of expansion efforts, the company would like to deliver internationalized email templates to best support local users in their native language. Ensure that you have configured `POSTMARK_SERVER_TOKEN` and `SEND_EMAIL_HOOK_SECRET` in your `.env` file.
```javascript
import { Webhook } from 'https://esm.sh/[email protected]'
@@ -650,7 +650,7 @@ Deno.serve(async (req) => {
const payload = await req.text()
const serverToken = Deno.env.get('POSTMARK_SERVER_TOKEN')
const headers = Object.fromEntries(req.headers)
- const base64_secret = Deno.env.get('AUTH_SEND_EMAIL_HOOK_SECRET')
+ const base64_secret = Deno.env.get('SEND_EMAIL_HOOK_SECRET').replace('v1,whsec_', '')
const wh = new Webhook(base64_secret)
const { user, email_data } = wh.verify(payload, headers)
@@ -717,7 +717,7 @@ Deno.serve(async (req) => {
</TabPanel>
{/* <TabPanel id="http-backup-email-provider" label="Add Backup Email Provider">
Your company is rapidly growing and depends heavily on email signups. You'd like to configure a backup email provider in case the email provider runs out of credits during your new product launch. Postmark and Sengrid are used as examples but in practice you can use any email provider.
-Ensure that you have configured `POSTMARK_SERVER_TOKEN`, `SENDGRID_API_KEY` and `AUTH_SEND_EMAIL_HOOK_SECRET` in your `.env` file.
+Ensure that you have configured `POSTMARK_SERVER_TOKEN`, `SENDGRID_API_KEY` and `SEND_EMAIL_HOOK_SECRET` in your `.env` file.
```javascript
import {
@@ -829,7 +829,7 @@ Deno.serve(async (req) => {
const postmarkServerToken = Deno.env.get("POSTMARK_SERVER_TOKEN");
const sendGridApiKey = Deno.env.get("SENDGRID_API_KEY");
const headers = Object.fromEntries(req.headers);
- const base64_secret = Deno.env.get('AUTH_SEND_EMAIL_HOOK_SECRET');
+ const base64_secret = Deno.env.get('SEND_EMAIL_HOOK_SECRET').replace('v1,whsec_', '');
const wh = new Webhook(base64_secret);
const {
user,
diff --git a/apps/docs/content/guides/auth/auth-hooks/send-sms-hook.mdx b/apps/docs/content/guides/auth/auth-hooks/send-sms-hook.mdx
index 2dab295db87..6a0a06a76d8 100644
--- a/apps/docs/content/guides/auth/auth-hooks/send-sms-hook.mdx
+++ b/apps/docs/content/guides/auth/auth-hooks/send-sms-hook.mdx
@@ -464,7 +464,7 @@ const sendTextMessage = async (
Deno.serve(async (req) => {
const payload = await req.text()
- const base64_secret = Deno.env.get('SEND_SMS_HOOK_SECRET')
+ const base64_secret = Deno.env.get('SEND_SMS_HOOK_SECRET').replace('v1,whsec_', '')
const headers = Object.fromEntries(req.headers)
const wh = new Webhook(base64_secret)
try {
@@ -527,12 +527,8 @@ Deno.serve(async (req) => {
Your company is expanding into Latin America and would like to use WhatsApp for higher deliverability. Write a hook to send WhatsApp messages to requests from the continent and SMS messages to all other numbers.
```javascript
-import {
- Webhook
-} from "https://esm.sh/[email protected]";
-import {
- readAll
-} from "https://deno.land/std/io/read_all.ts";
+import { Webhook } from "https://esm.sh/[email protected]";
+import { readAll } from "https://deno.land/std/io/read_all.ts";
import * as base64 from "https://denopkg.com/chiefbiiko/base64/mod.ts";
const accountSid: string | undefined = Deno.env.get("TWILIO_ACCOUNT_SID");
@@ -580,7 +576,7 @@ const sendMessage = async (
Deno.serve(async (req) => {
const payload = await req.text();
- const base64_secret = Deno.env.get("SEND_SMS_HOOK_SECRET");
+ const base64_secret = Deno.env.get("SEND_SMS_HOOK_SECRET").replace('v1,whsec_', '');
const headers = Object.fromEntries(req.headers);
const wh = new Webhook(base64_secret);
try {