Postgres backend
By integrating Supabase with Vercel, developers can leverage a Supabase Postgres Database, Auth, and Storage, Edge functions and Realtime while benefiting from Vercel's hassle-free deployment capabilities.
Some of the benefits from using this integration are:
For more information on pricing, click here.
When your project is up and running, click Open in Supabase button, go to the Table Editor, create a new table and insert some data.
Alternatively, you can run the following snippet in your project's SQL Editor. This will create a countries table with some sample data.
-- Create the tablecreate table notes ( id bigint primary key generated always as identity, title text not null);
-- Insert some sample data into the tableinsert into notes (title)values ('Today I created a Supabase project.'), ('I added some data and queried it from Next.js.'), ('It was awesome!');
alter table notes enable row level security;Make the data in your table publicly readable by adding an RLS policy:
create policy "public can read notes"on public.notesfor select to anonusing (true);Use the create-next-app command and the with-supabase template, to create a Next.js app pre-configured with:
Start by connecting to your existing project and then run vercel link in the CLI to link to the project locally.
Run vercel env pull .env.development.local to make the latest environment variables available to your project locally.
Create a new file at app/notes/page.tsx and populate with the following.
import { createClient } from '@/utils/supabase/server';
export default async function Notes() { const supabase = await createClient(); const { data: notes } = await supabase.from("notes").select();
return <pre>{JSON.stringify(notes, null, 2)}</pre>}This will select all the rows from the notes table in Supabase and render them on the page.
Run the development server with npm run dev, go to http://localhost:3000/notes in a browser and you should see the list of notes.
When your project is up and running, click Open in Supabase button, go to the Table Editor, create a new table and insert some data.
Alternatively, you can run the following snippet in your project's SQL Editor. This will create a countries table with some sample data.
-- Create the tablecreate table countries ( id bigint primary key generated always as identity, name text not null);-- Insert some sample data into the tableinsert into countries (name)values ('Canada'), ('United States'), ('Mexico');
alter table countries enable row level security;Make the data in your table publicly readable by adding an RLS policy:
create policy "public can read countries"on public.countriesfor select to anonusing (true);Create a SvelteKit app using the npm create command.
npx sv create myappThe fastest way to get started is to use the supabase-js client library which provides a convenient interface for working with Supabase from a SvelteKit app.
Navigate to the SvelteKit app and install supabase-js.
cd myapp && npm install @supabase/supabase-jsStart by connecting to your existing project and then run npx vercel link in the CLI to link to the project locally.
Run npx vercel env pull .env.development.local to make the latest environment variables available to your project locally.
Create a src/lib directory in your SvelteKit app, create a file called supabaseClient.js and add the following code to initialize the Supabase client with your project URL and public API (anon) key:
import { createClient } from '@supabase/supabase-js'import { SUPABASE_ANON_KEY, SUPABASE_URL } from '$env/static/private'
export const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY)Use load method to fetch the data server-side and display the query results as a simple list.
Create +page.server.js file in the src/routes directory with the following code.
import { supabase } from "$lib/supabaseClient";
export async function load() { const { data } = await supabase.from("countries").select(); return { countries: data ?? [], };}Replace the existing content in your +page.svelte file in the src/routes directory with the following code.
<script> let { data } = $props();</script>
<ul> {#each data.countries as country} <li>{country.name}</li> {/each}</ul>Run the development server with npm run dev, go to http://localhost:5173 in a browser and you should see the list of countries.
For more information on pricing, click here.
These variables provide essential configuration details such as the database connection URL, authentication credentials, and keys for accessing Supabase services.
By setting these variables appropriately, applications can establish connections to the database and securely interact with Supabase APIs.
Please exercise extreme caution with any environment variables from Supabase, especially any environment variables containing secret values.
Full list of variables installed:
POSTGRES_URLPOSTGRES_PRISMA_URLPOSTGRES_URL_NON_POOLINGPOSTGRES_USERPOSTGRES_HOSTPOSTGRES_PASSWORDPOSTGRES_DATABASESUPABASE_SERVICE_ROLE_KEYSUPABASE_ANON_KEYSUPABASE_URLSUPABASE_JWT_SECRETNEXT_PUBLIC_SUPABASE_ANON_KEYNEXT_PUBLIC_SUPABASE_URLFramework specific prefixes such as NEXT_PUBLIC_* can be modified via the Supabase dashboard.