Skip to main content

Use Supabase Auth with Next.js

Quickstart

  1. Create a new Supabase project

    Head over to database.new and create a new Supabase project.

    Your new database has a table for storing your users. You can see that this table is currently empty by running some SQL in the SQL Editor.

     select * from auth.users;
  2. Create a Next.js app

    Use the create-next-app command and the with-supabase template, to create a Next.js app pre-configured with:

    Explore drop-in UI components for your Supabase app.

    UI components built on shadcn/ui that connect to Supabase via a single command.

    Explore Components

    npx create-next-app -e with-supabase
  3. Declare Supabase Environment Variables

    Rename .env.example to .env.local and populate with your Supabase connection variables:

    Project URL: https://<project-ref>.supabase.co (find yours in the dashboard)

    Publishable key: sb_publishable_... (find yours in the dashboard)

    NEXT_PUBLIC_SUPABASE_URL=your-project-url
    NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY=sb_publishable_... key

    Get API details

    To interact with data in database tables, you use the client libraries that wrap the auto-generated Data API endpoints, authenticating using the Project URL and key from the project Connect dialog.

    Project URL: https://<project-ref>.supabase.co (find yours in the dashboard)

    Publishable key: sb_publishable_... (find yours in the dashboard)

    Note

    See API keys for a full explanation of all key types, their uses, and where to find them.

  4. Start the app

    Start the development server, go to http://localhost:3000 in a browser, and you should see the contents of app/page.tsx.

    To sign up a new user, navigate to http://localhost:3000/auth/sign-up, and click Sign up.

    npm run dev

Learn more