Dev Portal Supabase Setup
Do you want to share your API documentation and keys with your Supabase users? Look no further! You can easily connect your existing Supabase authentication with your Developer portal by following the guide below.
Tip
Using Vercel and NextJS? You can skip all of the steps below by
cloning our NextJS project!
Just fill in the .env.local
file and you will be ready support Supabase Auth.
Pre-requisites#
This guide assumes you already have the following:
- A Supabase project
- A basic understanding of Supabase Auth
- You can read their documentation to learn more
- Your Supabase anon key and project URL
- You can find these under Project Settings > API
- “User signups” must be enabled on your project
- You can find this under Project Settings > Auth
1/ Supabase Authentication App Setup#
This section will show you how to build an application to enable users to Sign Up, Sign In, and Sign Out of your Supabase project. If you already have an application that does this, you can skip to the next section.
The easiest way to get started with Supabase Auth is to use one of their Quickstart guides. In this tutorial, we will be using their Next JS quickstart (repo). Unfamiliar with Next JS? Try out the Next JS foundations course.
Once your repo and environment variables are setup, you should see the following
Once you are ready, deploy your project to production.
2/ Configure Auth on Your Supabase Project#
Grab the URL of your Vercel deployment and head over to the Supabase dashboard. Navigate to Authentication > URL Configuration > Site URL and paste in the full URL (ex. https://nextjs-with-supabase-xi-seven.vercel.app) in the Site URL field.
3/ Configuring Your Developer Portal To Use Supabase Auth#
From the Files view on your Zuplo project, navigate to the dev-portal.json
file under Config
. This is the configuration view for your Zuplo Developer
Portal. Zuplo will automatically generate a developer portal from your OpenAPI
spec.
Change the Provider from Demo
to External
. You will see two new fields
appear: Login URL
and Logout URL
. These correspond to the /login
and
/auth/sign-out
endpoints on your Supabase Auth App. Fill in the URLs of these
endpoints (ex. https://nextjs-with-supabase-xi-seven.vercel.app/login
). Your
developer portal will navigate to these pages to create and end sessions. Your
Authentication Settings should look like this once you are done:
Or in the JSON file:
4/ Grab Your Zuplo API key#
Before we leave the Zuplo Portal, you’ll need to grab your Zuplo API key. This key is used to securely connect your Supabase Auth App with the Developer Portal. From the side nav, go to your Project Settings and then click on Zuplo API Keys. Copy your API key.
5/ Connecting Your Supabase Auth App to the Dev Portal#
This section will explain how to integrate your Supabase Auth App and your Developer Portal to support Email and Password authentication. You can view the complete code in this sample repo.
Getting Started#
The Developer Portal will navigate users to your Login URL
with a special
query parameter called the session-create-url
attached. This query parameter
is the endpoint your Supabase Auth App must call in order to create a session on
the Developer Portal.
Sign Up Support#
Follow the steps below to learn how to support users signing up for your Supabase Project via the Developer Portal. You will be working on your Supabase Auth App codebase from earlier.
-
Add the Zuplo API key you just copied to the
.env.local
fileZUPLO_API_KEY=<your-key-here>
-
Navigate to the file for your Login page(
app/login/page.tsx
) -
In the props of your component, add
[searchParams](https://nextjs.org/docs/app/api-reference/file-conventions/page#searchparams-optional)
so you can read thesession-create-url
endpoint. -
Update your Sign Up button to forward the
session-create-url
to the sign-up endpoint -
Open your Sign Up route handler (
app/auth/sign-up
) and replace thesupabase.auth.signUp
call with the following -
Open your Callback route handler (
app/auth/callback
) and replace the code with the following -
Deploy your code (make sure to set an environment variable for you ZUPLO_API_KEY). Make sure the deployment URL matches the ones provided in your
dev-portal.json
. -
Once deployed, navigate to your Dev Portal (you can find the link the header of the Developer Portal Settings) and click the “Sign In” button at the top right
-
You should be redirected to your Supabase Auth App. Enter the email and password and click “Sign Up”.
-
A email verification link will be sent to your email. Open the email and click the confirmation link
-
You will be redirected back to the Dev portal and be signed into your Supabase account!
Sign in Support#
Now that you have created your first user, follow the guide below to allow them to sign into your Supabase project via the Developer Portal
-
Navigate to the file for your Login page(
app/login/page.tsx
) -
Add a Sign In button after the password input field
-
On your
form
element, change theaction
to pass thesession-create-url
to the/auth/sign-in
route handler. -
Open your Sign In route handler (
app/auth/sign-in
) and replace the code with the following -
Deploy your code (make sure to set an environment variable for you ZUPLO_API_KEY) and navigate to your Dev Portal. Then click the “Sign In” button
-
You should be redirected to your Supabase Auth App. Enter the email and password of an existing user and click “Sign In”.
-
You will be redirected back to the Dev portal and be signed into your Supabase account!
Sign Out Support#
You successfully created a user and signed up. Follow the guide below to learn how to sign them out.
-
Navigate to your Sign Out route handler (
app/auth/sign-out
) and add the following function -
Deploy your code and navigate to your Dev Portal. Sign in if you aren’t already. Then click your user icon and “Logout”
-
You should now be signed out of your Supabase Account
(Optional) Additional Auth Provider Support via Supabase#
Supabase allows you to connect many different Auth Providers. Follow the steps below to enable your users to sign up via Github. Note: You need to have completed the Sign Up Support section above first
-
Follow this Supabase guide to configure your project to support GitHub Auth
-
Create a new file called
GithubLogin.tsx
in yourapp/login
directory and paste in the following code -
In your Login Page (
app/login/page.tsx
), add the following code above the Sign Up buttonYou should now see a GitHub button on your login page
-
Deploy your code and navigate to your Dev Portal. Then click the “Sign In” button
-
You should be redirected to your Supabase Auth App. Click the “GitHub” button
-
You will be redirected to the GitHub OAuth flow. Sign into GitHub if you aren’t already, and navigate through the flow
-
You will be redirected back to the Dev portal and be signed into your GitHub account!
Wrap Up & Next Steps#
You can now use Supabase Auth to login to your Zuplo Developer Portal. Here’s some steps to try next:
- Elevate your API and Developer Portal experience with a custom domain to match your Supabase Auth App. Get started with our Builder plan today!
- Want to get more out of your Developer Portal? You can setup API Key Authentication to allow your new users to manage their keys in the Developer Portal directly!