Login
Tutorials

Start learning from the beginning.

Local Supabase Auth Setup

J
Jonathan Gamble
Published Updated 4 min read

There doesn't seem to be a lot of clear info online for setting up Authentication on localhost, so I thought I would write one. I'm currently trying to develop my next project local-first, which is good practice. Here are few things I'm learning along the way.

ENV Files#

Add your Client ID and Secret to your .env file, as you don't want the info readily available on GitHub.

TypeScript
GOOGLE_CLIENT_ID=...
GOOGLE_CLIENT_SECRET=...

TOML File#

Edit your config.toml file to add your auth inside env() functions like so:

Text
[auth.external.google]
enabled = true
client_id = "env(GOOGLE_CLIENT_ID)"
secret = "env(GOOGLE_CLIENT_SECRET)"
# Overrides the default auth redirectUrl.
redirect_uri = "http://localhost:54321/auth/v1/callback"
# Overrides the default auth provider URL. Used to support self-hosted gitlab, single-tenant Azure,
# or any other third-party OIDC providers.
url = ""

Package.json#

Add a stop and start command like sb:start and sb:stop to your package.json for easy use.

TypeScript
"scripts": {
    "dev": "vite dev",
    "build": "vite build",
    "preview": "vite preview",
    "test": "playwright test",
    "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
    "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
    "test:unit": "vitest",
    "lint": "prettier --plugin-search-dir . --check . && eslint .",
    "format": "prettier --plugin-search-dir . --write .",
    "sb:stop": "npx env-cmd npx supabase stop",
    "sb:start": "npx env-cmd npx supabase start"
},

If you use a Linux system or Mac, you should be able to use something like:

Text
source ./.env && npx supabase start

This depends on where your .env file is located.

However, if you use Windows, you will need to install env-cmd first:

Text
npm i -D env-cmd

then use this command instead:

Text
npx env-cmd npx supabase start

You will need load the .env file for both stop and start. Now you can use:

Text
npm run sb:stop
npm run sb:start

Callback#

Make sure to use:

Text
http://localhost:54321/auth/v1/callback

as your callback URL. This doesn't seem to be clear anywhere. For Google, i.e., you need to add this to your "Authorized redirect URIs" after you follow the Google Setup.

Now you can Login with Google using only a Localhost setup.

J

Comments

Share a thought or join the conversation.

Sign In to comment or reply.

Published Updated 3 min read
Published Updated 7 min read
Published Updated 9 min read
Newsletter

Get updates on future FREE tutorials, paid courses, and new blog posts!

Table of Contents

Select a title to jump. Use arrows to expand.

Tags

Explore posts by topic.