Edge Function cannot insert into table with RLS even using Service Role Key

await supabase.from("pre_login").insert({
user_id,
ip_address,
user_agent,
token,
expires_in
});
await supabase.from("pre_login").insert({
user_id,
ip_address,
user_agent,
token,
expires_in
});
I am using the Service Role Key inside the Edge Function. Previously I added policies, but even then the insert didn’t work.
9 Replies
garyaustin
garyaustin4w ago
If you are truly service_role then RLS will not matter. So either you are not service_role or you are getting some other error.
{[(1)]}
{[(1)]}OP4w ago
const supabase = createClient(Deno.env.get("SUPABASE_URL"), Deno.env.get("SUPABASE_SERVICE_ROLE_KEY"));
const supabase = createClient(Deno.env.get("SUPABASE_URL"), Deno.env.get("SUPABASE_SERVICE_ROLE_KEY"));
"Failed to insert pre_login record: "new row violates row-level security policy for table "pre_login"
No description
{[(1)]}
{[(1)]}OP4w ago
No description
ihm40
ihm404w ago
have you by any chance moved to jwt signing keys?
garyaustin
garyaustin4w ago
What do you do with the client after that point, before the insert?
{[(1)]}
{[(1)]}OP4w ago
Im fixed Sorry for wasting your time.
ihm40
ihm404w ago
no worries, would you mind sharing what was the issue just to help people in the future who experience similar issues?
{[(1)]}
{[(1)]}OP4w ago
I first use the anon client to authenticate the user and get their ID. After that, I switch to a separate client with the Service Role Key to insert into pre_login. The admin client is only used for the insert, not for login.
ihm40
ihm404w ago
makes sense, thanks

Did you find this page helpful?