Database updates
Create a created at column for all tables
Signup and password resets needs to have a special url for a valid auth session
{{ .SiteURL }}/auth/confirm?token_hash={{ .TokenHash }}&type=recovery
We need to explain how the user signup authorization workflow works. First, users signup for an account, then they will receive an email, after they click the link in the email to confirm it is them they will be redirected to a onboarding page and in the background a call is made to Stripe to create a new customer record from them, return the customer id, and adds it to their accounts table.
It’s important to note that we use Supabase Server-Side Auth for Next.js for improved security and auth flow. There’s many layers to it, which are covered in the support document below,.
In app/auth/confirm/route.js you will find a redirect that redirect people to the onboarding page. It’s important to note that this file handles new signups, after a user signs up and receives the link in their email to confirm, it sends the request to this file which handles the auth, then redirects the user to the onboarding page where we then add them to Stripe by creating a new user and we then store their Stripe Customer ID in their accounts details for later processing.
One important thing, whether we are testing locally or working on the live site, is to pay close attention to the link in the email, change {{ .ConfirmationURL }}
to {{ .SiteURL }}/auth/confirm?token_hash={{ .TokenHash }}&type=email
. On Local, this means adding the following to the config.toml file.
[auth.email.template.confirmation]
subject = "Local DEMO"
content_path = "./supabase/templates/invite.html"
and adding the file to that folder, here’s are demo of the code