"The schema must be one of the following: api"
I am moving from public schema to api schema. So I made the schema api also exposed api in config.toml and set it as extra search path
Made this function:
But for some reason it doesnt work anymore, worked perfectly when it was in public.
26 Replies
How are you calling it?
Did you grant access to the schema? https://supabase.com/docs/guides/api/using-custom-schemas
const { data, error } = await supabase.rpc('get_user_profile_with_subjects').single();
Yes I did, I have the feeling that it still queries public.get......
But I thought modifying the search path in config.toml would change that
You need to add .schema('api') to the call.
I see, do you know if there is a way to set api as default?
When you createClient you can set the default schema for that client.
.schema doesn't exist btw
Will try that thanks
It does.
Ah weird my ide didn't recognize it
Thanks!
The search_path did not work because the Client uses public.xxx for all calls unless you override it. It does not just call the function name.
Ahh makes sense thanks a lot
Hmm really weird, after setting createClient to schema api i get
Property 'auth' does not exist on type 'PostgrestClient<any, "api", any>'.deno-ts(2339)
for const { data: newUser, error: createError } = await supabase.auth.admin.createUser({
worked around it by not setting on schema and insttead on queries that need it. Is this a bug that should be reported or am i missing something?
Not sure. One normally does not do auth calls with service_role on a shared client (doing other calls than auth admin) so maybe a something missed.
That was the only way to do schemas until about a year ago so surprised it would not have been hit though.
Well same for
this would surely be discovered?
Or is that "just" a typescript error....
Unfortunatly not, fails in runtime Cannot read properties of undefined (reading 'onAuthStateChange')
I see deno in your error above. Is this an edge function?
Yes responsible for creating users on a admins request.
The last snippet is from the front end
Same for Property 'getChannels' does not exist on type 'PostgrestClient<any, "api", any>'.ts(2339)
I'm not getting any error but I don't use typescript.
onAuthStateChange works fine with db: schema option.
I see, does it fail for you in runtime
Ah okay.
Really weird
export const supabase = createClient(CF_SUPABASE_URL, CF_ANON_KEY).schema('api');
You did it like this right?
no
Ah now I am going to feel really stupid haha, what did i do wrong

It is one of many createClient options.
import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://xyzcompany.supabase.co', 'publishable-or-anon-key', {
// Provide a custom schema. Defaults to "public".
db: { schema: 'other_schema' }
}) oh just found this haha
(method) SupabaseClient<any, "public", any>.schema<"api">(schema: "api"): PostgrestClient<any, "api", any>
Select a schema to query or perform an function (rpc) call.
The schema needs to be on the list of exposed schemas inside Supabase.
@param schema — The schema to query
Should have double checked the docs but honestly this jsdoc is confusing af
Well glad you showed the .schema added on. I would have never guessed that on createClient. That is used before .rpc and .from.
Yeah in that case it makes sense it's also there for createClient since you use that through a ref. My bad, thanks for thinking along!!