Reputation: 11
I'm new to Supabase and experimenting with building a new Next.js app using it. Below are the steps that I've taken thus far that led to the error:
I initialized a fresh Next.js app using npx create-next-app
I installed Supabase using npm i @supabase/supabase-js.
I created a .env.local file and added my Supabase database API URL and anon key as NEXT_PUBLIC environment variables.
I initialized Supabase in a /util/supabase.js
file with the following code:
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;
const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;
export const supabase = createClient(supabaseUrl, supabaseAnonKey);
I attempt to query my "Course" database table using the following code in my /pages/index.js
file:
import { supabase } from "../lib/supabaseClient";
export default function HomePage({ courses }) {
return <div>Under Construction...</div>;
}
export async function getStaticProps() {
const { data, error } = await supabase.from("course").select("*");
console.log(data, error);
return {
props: {
courses: data,
},
};
}
When I do the above, however, I get error 42501
: "Permission denied for schema public."
I recognize that I'm doing something wrong here, but I've read through the docs and I have no idea what it is. Since this is my very first experience with Supabase, I'd very much appreciate any help that someone can provide about what I need to do differently to get things going.
Thanks very much, Sulaim
Upvotes: 1
Views: 4846
Reputation: 1
I think you just have to grant access to your tables or extensions, this has worked for me.
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO authenticated;
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO anon;
Upvotes: 0
Reputation: 1
I had the same error, in my case editing table setting in Supabase table editor worked. I unchecked "Enable Row Level Security (RLS)".
Upvotes: 0