Skip to content

BE-M1-01 · Invite and sign-in emails, redirect URLs, link expiry, email limits, password change and SITE_URL on a hosted project

Why: Supabase Auth sends the invite email and checks its link (D98). The local stack takes these settings from supabase/config.toml, but a hosted project takes them only from its dashboard, so each one is set by hand (L0). Run it on staging before the first invitation is sent there, and on production at cutover.

ID BE-M1-01 · Level L0 · Issue #454, #600, #650

On the hosted project, the invite email is Indonesian and its link opens /auth/confirm on the address apps/web names in its SITE_URL variable (R-ACC-93, R-ACC-100, #600), that address and its /auth/confirm and /welcome are allowed redirect URLs, an email link lasts 24 hours (R-ACC-94; a password-reset link too, by D98), Auth sends up to 60 emails an hour (#600), a password change needs a recent sign-in (R-ACC-246), the sign-in link a re-invited login gets is Indonesian and reads as an invitation (R-ACC-273, D101), and one email gets at most one such link every 60 seconds (#650).

  • The slice's pull request for #454 is merged, so supabase/templates/invite.html is on main; for blocks 8 and 9, #650's is too, so supabase/templates/magic_link.html is. A project that ran blocks 1 to 7 already runs only blocks 1, 8 and 9.
  • You are in ~/opleet-v2/opleet on main, up to date.
  • The project's Site URL is apps/web's address, https://<APP_HOST>: on staging the Vercel address TL-M0-21 set (<VERCEL_URL>). On production, set it at cutover first.
  • The email's link is built from {{ .RedirectTo }}, which apps/web takes from its server-only variable SITE_URL, never from the request; with SITE_URL unset it sends none and Auth uses the Site URL. Each deployed environment's SITE_URL is that environment's own address: <PRODUCTION_SITE_URL>, <STAGING_SITE_URL>, and for previews <PREVIEW_SITE_URL>, a fixed branch alias of apps/web on Vercel (such as the address of the staging branch), so every invitation sent from any preview opens that one alias. Each is a full origin such as https://<APP_HOST>, with no path or trailing slash.
  • On staging, <PREVIEW_HOST_PATTERN> matches this Vercel project's own preview addresses only, such as <VERCEL_PROJECT>-*-<VERCEL_TEAM>.vercel.app, and must contain <PREVIEW_SITE_URL>'s host. Never a bare wildcard on a shared domain, such as *.vercel.app or **.vercel.app: anyone can deploy there, and Auth would send an invitation's token to their site. Production has no previews: skip it there.
  • The project sends email through its own SMTP server (Authentication › Emails › SMTP Settings shows it on). Supabase's built-in sender has a fixed, lower limit, so block 5 needs it.
  • Below, <PROJECT> is opleet-v2-staging or the production project, and every page is in that project in the Supabase dashboard. Nothing here needs a key or a password.

Write down, for Undo: the Invite user and Magic link templates' subjects, the Minimum interval per user, the Redirect URLs list, the Email OTP Expiration, the Rate limit for sending emails and whether Secure password change is on. Don't copy the template body; Undo restores Supabase's default.

Copy the template without its leading comment:

Terminal window
sed '/^<!--/,/-->$/d' supabase/templates/invite.html | pbcopy

Authentication › Emails › Templates › Invite user:

  • Subject: Undangan bergabung dengan Opleet, exactly as in supabase/config.toml under [auth.email.template.invite].
  • Body: select all, paste. Save.

Authentication › URL Configuration › Redirect URLs › Add URL, once for each:

  • https://<APP_HOST>
  • https://<APP_HOST>/auth/confirm
  • https://<APP_HOST>/welcome
  • staging only: https://<PREVIEW_HOST_PATTERN>/**

Keep what is already there, such as staging's https://<VERCEL_URL>/**. If the list holds a wildcard on a shared domain, such as https://*.vercel.app/**, stop and paste it on #600 before you save. Save.

Authentication › Sign In / Providers › Email › Email OTP Expiration: 86400. Save.

Authentication › Rate Limits › Rate limit for sending emails: 60 emails per hour. Save.

Authentication › Sign In / Providers › Email › Secure password change: on. Save.

In Vercel, apps/web's project › Settings › Environment Variables, add SITE_URL (not NEXT_PUBLIC_, so it stays on the server), one entry per environment:

  • Production: <PRODUCTION_SITE_URL>. On staging's run, skip it until cutover.
  • Preview: <PREVIEW_SITE_URL>. Production's run skips it.
  • For the staging deployment, if it is its own Vercel environment or branch: <STAGING_SITE_URL>.

Each value must be one of block 3's redirect URLs, or match <PREVIEW_HOST_PATTERN>. Save, then redeploy so the variable reaches the server.

Copy the template without its leading comment:

Terminal window
sed '/^<!--/,/-->$/d' supabase/templates/magic_link.html | pbcopy

Authentication › Emails › Templates › Magic link:

  • Subject: Undangan kembali ke Opleet, exactly as in supabase/config.toml under [auth.email.template.magic_link].
  • Body: select all, paste. Save.

Authentication › Sign In / Providers › Email › Minimum interval per user: 60 seconds. Save. The local stack keeps 1 s so journeys can resend at once; a hosted project keeps 60 s.

  • Block 2: the template's preview shows "Anda diundang ke Opleet" and a link "Terima undangan"; the page says the template was saved.
  • Block 3: the list shows the new URLs, each with your <APP_HOST>, beside the ones that were there.
  • Block 4: the field shows 86400 after saving, with no warning that it is above the maximum (604800).
  • Block 5: the field shows 60 after saving.
  • Block 6: the switch stays on after saving.
  • Block 7: Vercel lists SITE_URL once for each environment you set, with its value hidden or shown as you entered it.
  • Block 8: the template's preview shows "Anda diundang kembali ke Opleet" and a link "Terima undangan"; the page says the template was saved.
  • Block 9: the field shows 60 after saving.

Reload each page:

  • Invite user shows the subject Undangan bergabung dengan Opleet, and its body has {{ .RedirectTo }}/auth/confirm?token_hash={{ .TokenHash }}&type=invite.
  • Redirect URLs lists https://<APP_HOST>, https://<APP_HOST>/auth/confirm and https://<APP_HOST>/welcome, and on staging https://<PREVIEW_HOST_PATTERN>/**.
  • Email OTP Expiration is 86400.
  • Rate limit for sending emails is 60.
  • Secure password change is on.
  • Vercel shows SITE_URL for each environment you set, and none of them is a wildcard.
  • Magic link shows the subject Undangan kembali ke Opleet, and its body has {{ .RedirectTo }}/auth/confirm?token_hash={{ .TokenHash }}&type=magiclink.
  • Minimum interval per user is 60.

The full proof is the first invitation sent through apps/web on this project: its email is in Indonesian, and its link opens https://<APP_HOST>/auth/confirm and then /welcome. On staging, one sent from a preview deployment opens <PREVIEW_SITE_URL>'s /auth/confirm. Log both with this run. For blocks 8 and 9, the proof is the first re-invitation of a removed member on this project: the email's subject is Undangan kembali ke Opleet, its link opens https://<APP_HOST>/auth/confirm and then the app, signed in, and Kirim ulang within a minute shows the rate-limit message. Log it on #650.

  • The body won't save, or the preview shows the comment: the paste picked up the file's first lines. Run block 2's command again and paste only what it copied.
  • Email OTP Expiration refuses 86400: stop and paste the message on #454; D98 sets 24 hours, so don't choose another value.
  • The link in a sent invite goes to the Site URL instead of SITE_URL's address: either SITE_URL is unset for that environment (block 7; redeploy after setting it), or its address isn't an allowed redirect URL, so Auth fell back to the Site URL. Compare it with block 3's list, and paste both on #600.
  • The link in a sent invite goes to localhost: the Site URL is wrong, not this step. Fix it under URL Configuration, then send again.
  • Rate limit for sending emails can't be changed, or says custom SMTP is needed: the project still uses Supabase's built-in sender. Stop and paste the message on #600; setting up SMTP is not this step.
  • Secure password change isn't on that page: look under Authentication › Sign In / Providers › Email for the same switch, then paste what you found on #600 so this step can be corrected.
  • Minimum interval per user isn't on that page: look under Authentication › Rate Limits for an interval between emails per user, set it to 60, and paste what you found on #650 so this step can be corrected.
  • An invite link opens /login with an error instead of /welcome: a redirect URL doesn't match exactly. Compare block 3's URLs with the address bar, and paste both on #454.

Set back what block 1 noted: the subjects, the default bodies (Invite user and Magic link › Reset to default, or Supabase's default templates), the Minimum interval per user, the Redirect URLs list, the Email OTP Expiration, the Rate limit for sending emails and Secure password change. Remove the SITE_URL entries block 7 added, and redeploy. Invite links already sent keep the expiry they were sent with.

One comment per run on #454, for blocks 5 and 6 and the preview redirect on #600, and for blocks 8 and 9 on #650: date · who · project · result · notes.