NanoBit
07/19/2022, 7:37 AMauth.role() = 'authenticated' works however, TO authenticated in RLS policy does not work FOR Prisma Client. (Supabase Client works for both)
More details in threadNeedle
07/19/2022, 7:37 AMNanoBit
07/19/2022, 7:43 AMNanoBit
07/19/2022, 9:29 AMjs
const [, results] = await prisma.$transaction([
setCurrentJWT(req),
prisma.customer.findMany(),
]);
const { data } = await supabaseServerClient({ req, res })
.from<definitions["customers"]>("customers")
.select("*");
console.log(results?.[0]);
console.log("supa side");
console.log(data?.[0]); // Single Customer obj
If I used TO authenticated,
js
console.log(results?.[0]); // undefined
console.log("supa side");
console.log(data?.[0]); // Single Customer obj
If I used auth.role() = 'authenticated',
js
console.log(results?.[0]); // Single Customer obj same as above
console.log("supa side");
console.log(data?.[0]); // Single Customer obj same as aboveNanoBit
07/19/2022, 9:30 AMrequest.jwt.claims and outputting it via SELECTNanoBit
07/19/2022, 10:06 AMauth.role() <> 'authenticated', and both logs show undefined meaning that it's this setting that's affecting the result.garyaustin
07/19/2022, 12:23 PMNanoBit
07/19/2022, 12:50 PMprisma with permissions on public schema only on all tables. (no bypass RLS).
> The auth.role() gets the data from the jwt claims, which evidently Prisma sets
yep, this was the initial intention.
> You can continue to use auth.role() or what ever replaces it in the future to read the jwt. It is needed in functions so can’t go away.
Oh I see! Although it's a little dirty compared to using the TO operator.
> PostgREST sets the user to anon or authenticated
I was reading about this and that they take the role from the jwt.role which auth.role() does reference.
https://postgrest.org/en/latest/auth.html#
My hypothesis right now is that, it does set the role properly, but the user does not change to the authenticated role for some reason. It does change to the logged-in user (via jwt), but does not set the status to authenticated.
I'll see if SET LOCAL ROLE authenticated; does somethingNanoBit
07/21/2022, 7:04 AMprisma acc that acts like authenticator class. Will post my solution later on the discussions for others: https://github.com/supabase/supabase/discussions/7659Needle
07/21/2022, 7:04 AM