Supabase Client Libraries
Supabase client for Next.js
Installation
Folder structure
1import { createBrowserClient } from '@supabase/ssr'
2
3export function createClient() {
4 return createBrowserClient(
5 process.env.NEXT_PUBLIC_SUPABASE_URL!,
6 process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
7 )
8}
Usage
This block installs a Supabase client for connecting your Next.js project to Supabase. It's designed for use with the App Router and fully supports server-side rendering (SSR).
If you've already set up your Supabase client—either using the npx create-next-app -e with-supabase
template or another method—you can continue using your existing setup.
Getting started
First, add a .env
file to your project with the following environment variables:
NEXT_PUBLIC_SUPABASE_URL=
NEXT_PUBLIC_SUPABASE_ANON_KEY=
-
If you're using supabase.com, you can find these values in the Connect modal under App Frameworks or in your project's API settings.
-
If you're using a local instance of Supabase, you can find these values by running
supabase start
orsupabase status
(if you already have it running).
This Supabase client is built for SSR with the Next.js App Router. If you're building a React SPA, use the React SPA client instead.