In this series, we’ll be covering how to use Supabase with Nuxt 3 to add auth to our apps. In this first article, we’ll go over how to set up Supabase in our Nuxt project.
Get notified when we release new tutorials, lessons, and other expert Nuxt content.
Authentication can be tricky to implement, but it lets us do so much in our apps.
In this series, we’ll be covering how to use Supabase with Nuxt 3 to add auth to our apps:
In this first article, we’ll go over how to set up Supabase in our Nuxt project.
Here are the main steps we’ll cover in this article:
The first step is to create our project in Supabase.
Head over to supabase.com:
New project
to create a projectDatabase password
somewhere safe if you plan to use the database in the future We don’t need this to get authentication working, and it can be easily reset later on if you forget it.Create new project
Now, you just wait! It can take a few minutes for Supabase to initialize everything your project needs.
Next, we need to set up Github as an OAuth provider:
Authentication
and then Providers
— you’ll see a big list of all the possible providers we can useGithub
sectionredirectURL
— we’ll need it for when we set up the Github OAuth appKeep the Github settings open in a tab, since we’ll need it shortly.
Next, we’ll configure a Github OAuth app that will allow our Supabase project to connect with Github on behalf of our users.
In a new tab, go to the OAuth Apps settings: https://github.com/settings/developers
settings
, then Developer Settings
at the very bottom, and then clicking on OAuth Apps
We’ll create a new OAuth App:
Create OAuth App
Application Name
Homepage
, or the redirectURL
— this part doesn’t affect the auth processredirectURL
we copied from Supabase for the Authorization Callback URL
Register Application
to create itBefore moving on, we need to grab two values:
Client ID
— we can always find this hereClient Secret
— click on Generate a new client secret
. To keep things secure, Github will only show this value to us once. Copy this value down or keep the tab open.Github also has great documentation for creating OAuth Apps.
Now we’ll take the two values from our Github App and use them to configure our Supabase Github provider:
Authentication
and then Providers
, then scroll down and expand the Github
sectionClient ID
and Client Secret
into the settingsClient Secret
@nuxtjs/supabase
moduleThe Supabase module for Nuxt 3 handles SSR and some other things for us, so it’s convenient to have.
Install and configure the module:
pnpm add -D @nuxtjs/supabase
— or the relevant command for whichever package manager you likenuxt.config.ts
export default defineNuxtConfig({
modules: [
'@nuxtjs/supabase',
],
});
We’re nearly there, we just need to connect our Supabase project to our Nuxt 3 app.
We do this through some environment variables:
.env
at the root of your directory — this is where all your environment variables liveSUPABASE_URL
and SUPABASE_KEY
to your .env
fileSUPABASE_URL="<URL>"
SUPABASE_KEY="<anon>"
Project Settings
then click on the API
sectionURL
under Project URL
and add it as the SUPABASE_URL
anon
key under Project API Keys
and add it as the SUPABASE_KEY
At this point we have a Nuxt 3 app with Supabase and Github configured exactly how need.
The next step is to use the Supabase API to log in and out of our app, which is what we’ll cover in the next article in this series.
Next Article: Logging in and out with Github