© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•14mo ago
MrScribbles

Getting 401 when connecting to local DB

Hello,
I'm getting a 401 error in my Next TS project when attempting to connect to my local supabase db.

Error: Either "typeerror failed to fetch" Or a 401 unauthorized, depending on which address I try to use.

I know that the DB is running, so I hope you can just provide me the correct local address. I am doing testing so I can't do this on the remote prod DB, I need the local one.

I've been trying different addresses in my local env file and none have worked. I'm showing the different ones I've tried below.

I'm on Windows, using the CLI, on Postgres. Please let me know if you need any other info.

Thank you so much!

local.env:


NEXT_PUBLIC_SUPABASE_URL=postgresql://postgres:postgres@localhost:54322/postgres


NEXT_PUBLIC_SUPABASE_URL=postgresql://postgres:postgres@127.0.0.1:54322/postgres

NEXT_PUBLIC_SUPABASE_URL=postgresql://postgres:[W4JRFvQ4CqM1wwuh]@db.kqnhzwgaypywymhqfbgd.supabase.co:5432/postgres


NEXT_PUBLIC_SUPABASE_URL=http://localhost:54323


got from https://github.com/vercel/nextjs-subscription-payments/blob/main/.env.local.example

NEXT_PUBLIC_SUPABASE_URL=http://127.0.0.1:54321

Page.tsx where I'm calling the API from:

"use client";

... // other code
import { createClient } from "@supabase/supabase-js";

useEffect(() => {
// Define the async function inside useEffect
const fetchData = async () => {
const supabase = createClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
);

// Fetch users from the "user12" table
const { data, error } = await supabase.from("user").select();

console.log("data:", data);

if (error) {
console.error("Error fetching users:", error);
return;
}

// Set the fetched data into state
setUsers(data);
};
GitHub
nextjs-subscription-payments/.env.local.example at main · vercel/ne...
Clone, deploy, and fully customize a SaaS subscription application with Next.js. - vercel/nextjs-subscription-payments
nextjs-subscription-payments/.env.local.example at main · vercel/ne...
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

timeout when connecting with dbeaver
SupabaseSSupabase / help-and-questions
4y ago
Error connecting to DB
SupabaseSSupabase / help-and-questions
3mo ago
connecting to external postgres db
SupabaseSSupabase / help-and-questions
4y ago
Connecting to DB with SQLAlchemy
SupabaseSSupabase / help-and-questions
3mo ago