Persistent PGRST301 error on a TEXT primary key and I'm completely stumped.

Hey everyone! I'm running into a persistent PGRST301 error on a TEXT primary key and I'm completely stumped. I've been debugging this for a while and have tried everything I can think of, including a full project restart The Goal: I'm using Clerk for auth with the recommended webhook integration. An Edge Function creates a user in my public.profiles table, where the id is the Clerk User ID When my client-side app queries the profiles table, it consistently fails.
Script// This query is being run from my app client-side
const { data, error } = await supabase
.from('profiles')
.select('kudos_balance')
.eq('id', 'user_...') // The user's Clerk ID
.single();
Script// This query is being run from my app client-side
const { data, error } = await supabase
.from('profiles')
.select('kudos_balance')
.eq('id', 'user_...') // The user's Clerk ID
.single();
{
"code": "PGRST301",
"message": "No suitable key or wrong key type"
}
{
"code": "PGRST301",
"message": "No suitable key or wrong key type"
}
My Setup: * public.profiles table has an id column of type TEXT. * This id column is set as the PRIMARY KEY. * My RLS policy for SELECT is correct for Clerk's JWTs:
USING ((auth.jwt() ->> 'sub') = id)
USING ((auth.jwt() ->> 'sub') = id)
What I've Already Tried (with no success): * Rebuilding the Primary Key: I've run ALTER TABLE ... DROP CONSTRAINT profiles_pkey CASCADE, followed by re-adding the primary key and all the foreign key constraints. The script completes successfully. * Forcing Schema Cache Reload: I've run NOTIFY pgrst, 'reload schema' after every schema change. * Full Project Restart: I performed a full project restart via the Supabase dashboard. The error still persists. * Verified Webhooks: The Clerk webhook is firing successfully and the user profile is being created perfectly in the profiles table. The data is definitely there. I feel like I'm in a weird state where the database schema is correct, but the PostgREST API layer is working off a stale cache that a restart didn't even fix. Has anyone ever seen an issue this persistent? Is there another way to force the API schema to refresh that I'm missing? Any suggestions would be amazing.
4 Replies
garyaustin
garyaustin5d ago
I think that error has to do with a bad JWT.
No description
LuckyDuck
LuckyDuckOP5d ago
Thank you so much, you gave me exactly what I needed to troubleshoot the rest. I simply missed a step, adding Clerk as a sign in provider and pasting the URL from Clerk. The JWT was valid and providing the right claims but Supabase wasn't seeing it as valid because of that one minor issue. How do I send a coffee?
garyaustin
garyaustin5d ago
Appreciate the thought but Supabase compensates us mods for our time.
LuckyDuck
LuckyDuckOP5d ago
Ok, I really appreciate that you unblocked me. You're a superstar

Did you find this page helpful?