Home

Install Supabase with Nuxt.js

Setting up supabase-js client library in a Nuxt.js app.

The fastest way to get started with supabase and Nuxt.js is to use the supabase-js client library, which provides a convenient interface for working with supabase from a Nuxt.js app. To use supabase-js with Nuxt.js, you can follow these steps:

1

Create a Nuxt.js app

Start by creating a new Nuxt.js project if you do not have one set up:

Terminal

_10
npx create-nuxt-app my-project
_10
cd my-project

2

Install Supabase client library

To install the @supabase/supabase-js package, you will need to run the following command:

Terminal

_10
npm install @supabase/supabase-js

2

Install Supabase client library

And finally we want to save the environment variables in a .env. All we need are the API URL and the anon key that you copied earlier.

.env

_10
SUPABASE_URL="YOUR_SUPABASE_URL"
_10
SUPABASE_KEY="YOUR_SUPABASE_ANON_KEY"

2

Install Supabase client library

Then let's install the only additional dependency: NuxtSupabase. We only need to import NuxtSupabase as a dev dependency:

Terminal

_10
npm install @nuxtjs/supabase --save-dev

3

Create some sample data

To create a table of countries with their timezones, you will first need to create a table in your Supabase database using SQL. You can use the following SQL statement to create a table called countries:

SQL_EDITOR

_10
-- this creates the table
_10
CREATE TABLE countries (
_10
id SERIAL PRIMARY KEY,
_10
name VARCHAR(255) NOT NULL
_10
);
_10
-- insert some sample data into new table
_10
INSERT INTO countries (name) VALUES ('United States');
_10
INSERT INTO countries (name) VALUES ('Canada');
_10
INSERT INTO countries (name) VALUES ('Mexico');

4

Start your app

Start the dev server by running the following commands:

Terminal

_10
npm run dev

5

Create client in app

Next, in your Nuxt.js app, create a file called supabase-client.js and add the following code to initialize the Supabase client and set your project's credentials:

lib/supabaseClient.js

_10
import { createClient } from '@supabase/supabase-js'
_10
_10
const supabase = createClient('https://xyzcompany.supabase.co', 'public-anon-key')