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
0 Replies