Supabase Authentication Flow
When a user authenticates on Shipped using Supabase Auth Magic link or Email & Password, it follows this flow.
The user provides the email (i.e xyz@user.com) and hits the Sign Up button
Supabase sends an email to xyz@user.com
The user clicks on the link included in the email
The browser opens the route
yourwebsite.com/supabase/auth/callback
with the code query parameter (?code=abc...
)The route exchanges the code for a session and saves the user into the database table
public.User
with the same ID as the Supabase Auth user.
Use the Supabase Auth user with Prisma
Supabase saves all authenticated users into the table auth.users
(where auth
is the schema, and users
the table name) of the Postgres database.
Shipped is configured to use Prisma as the ORM (Object Relational Mapping), and it uses the schema public
to create all the tables that are needed by your product.
By default, the prisma.schema
file that comes with Shipped, includes a public.User
table, with this schema:
This schema is coming from NextAuth, but you can also use it if you use Supabase Auth.
If you need to add new tables to your database, which refer to a user, use can use a schema similar to the one described below.
For instance, if your product generates screenshots of websites, you'll probably have a public.Screenshot
table, defined in the prisma.schema
file as follows:
Notice the foreign key relation between the table Screenshot
and the table User
, based on userId
(User.id
-> Screenshot.userId
).
If you need to retrieve the screenshots of the user, use this sample code:
This way, you'll be able to combine Supabase Auth, with the Prisma-handled tables and link the users using the Supabase Auth user id.
Last updated