LOCAL setup db error: No suitable key or wrong key type

Hi, I'm experiencing an issue in local setup where trying to access my supabase table from my client returns with the error {"code": "PGRST301", "details": null, "hint": null, "message": "No suitable key or wrong key type"}. This error does not occur in Production. When setting up my local, I've already followed the appropriate steps like setting up Docker, running db pull && db migration up to recreate my production schema in my local. In my table, I've already enabled RLS to enable SELECT on my table for authenticated users with the 'using' condition as '(( SELECT auth.uid() AS uid) = user_id)'. From my client, I am calling my table like so: try { const { data, error } = await supabase.from("table").select(); if (error) throw error; return data; } catch (e) { console.log(e); } Any help would be appreciated. Thank you
18 Replies
inder
inder•3d ago
What is your cli version? Which key are you using in your createClient call?
Ryry💻🤓
Ryry💻🤓OP•3d ago
Hey @inder , I'm on v2.48.3. My createClient call is using: Local API url retrieved from 'supabase status', and the Anon key ----- const supabaseUrl = process.env.EXPO_PUBLIC_SUPABASE_URL as string const supabaseAnonKey = process.env.EXPO_PUBLIC_SUPABASE_ANON_KEY as string export const supabase = createClient<Database>(supabaseUrl, supabaseAnonKey, { auth: { storage: AsyncStorage, autoRefreshToken: true, persistSession: true, detectSessionInUrl: false, }, })
inder
inder•3d ago
Are you using clerk? https://discord.com/channels/839993398554656828/1428462874531201105 If not have you enabled signing_keys in config.toml?
Ryry💻🤓
Ryry💻🤓OP•3d ago
I am not using Clerk. I have not enabled signing_keys. I just tried enabling it, but the error persists. In my config.toml, I've uncommented this line: signing_keys_path = "./signing_keys.json" I guess it's probably failing because i don't have signing_keys.json in my project. Are you able to point me to where I can set this up? Another question is why would this fail locally and not in production? (Sorry, I am a beginner at this)
inder
inder•3d ago
No this isn't necessary just wanted to know if you have it enabled. This needs a separate keys file to be generated. You can disable it if you're not using it You can try installing the latest version of cli and try with that. Use npx. Its easier to manage cli versions
Ryry💻🤓
Ryry💻🤓OP•2d ago
Hi @inder, I've updated my cli version to 2.51.0, but the error persists. As you shared above, it's likely due to a JWT issue. One thing to note probably is that when my client calls the table, the user might not be authenticated. If I understand correctly, the assuming role would be anon . I've tried amending the RLS to allow anon roles for SELECT access, or even disabled RLS completely for that table, but the issue still persists.
inder
inder•2d ago
I tried with a new project on my end and didn't face this issue. Try taking down containers, remove supabase volumes and then start stack again. Also are you using the old anon key or the new publishable key? Both should work, just trying to reproduce the same issue locally
Ryry💻🤓
Ryry💻🤓OP•2d ago
I am using the old anon key, the one taken from project > settings > API Keys > Legacy API Keys
No description
inder
inder•2d ago
Are you using the one from cloud locally? local supabase has its own anon key Run npx supabase status -o env | grep ANON_KEY You will get output like this. use the key value
ANON_KEY=<KEY>
ANON_KEY=<KEY>
Ryry💻🤓
Ryry💻🤓OP•2d ago
That was the issue! I didn't know local uses its own anon key.. Thank you so much for your help.
inder
inder•2d ago
Yeah. Also just a heads up service role key, db password everything is different for local supabase.
Ryry💻🤓
Ryry💻🤓OP•2d ago
I am next facing an issue which I believe should be a simple thing I am missing. I am now getting a permission denied error when trying to run select on my table.: LOG {"code": "42501", "details": null, "hint": null, "message": "permission denied for table ..."} What I don't understand is being denied permission even when disabling RLS, or setting the RLS's target roles to 'public'. Is this related to having different keys on local once again? Below is my RLS: alter policy "Enable users to view their own data only" on "public"."table" to anon, authenticated, postgres using ( (( SELECT auth.uid() AS uid) = user_id) );
inder
inder•2d ago
Disabling RLS should have worked. What if you simply set it to true inside using block
using ( true );
using ( true );
Currently, you're checking for auth.uid() even for anon user. if your goal is complete SELECT access, this won't work For users who should only view their own data, you can simply set the policy to authenticated role only
for SELECT
to authenticated
using (SELECT auth.uid() = user_id);
for SELECT
to authenticated
using (SELECT auth.uid() = user_id);
Ryry💻🤓
Ryry💻🤓OP•2d ago
Tried disabling again, or amending policy to using ( true ); , but still getting permission denied. For my particular use case, data in this table can be accessed by both anon users (not logged in yet) and authenticated users.
inder
inder•2d ago
Try using service role key. That bypasses RLS If that doesn't work, then there is some issue with grants
Ryry💻🤓
Ryry💻🤓OP•this hour
I've managed to resolve this. I noticed that in my migration scripts, there are a bunch of revoke statements that basically removes grants from my anon, authenticated and service_role roles. I've commented those out which fixed the issue. If I want these migration scripts to be updated in prod, can I simply do a db push? I was wondering if simply pushing changes in old migration scripts to prod is considered best practice, or is there a better way? Thanks!
inder
inder•21h ago
Can you create another post for this specific issue? I have noticed some other users coming up with the same issue. Might help someone else in the future

Did you find this page helpful?