https://supabase.com/ logo
#help
Title
# help
e

emellum

05/06/2022, 11:18 PM
Is there a way to debug when RLS isn't working as expected? I have a simple uid() = id policy. The id in this table is matching what I have in my auth.users user id column, but I do not see records returned. Would like to drill in deeper to see why
n

Needle

05/06/2022, 11:18 PM
Hello @emellum! This thread has been automatically created from your message in #843999948717555735 a few seconds ago. We have already mentioned the @User so that they can see your message and help you as soon as possible! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ``...`` menu) and select "Leave Thread" to unsubscribe from future updates. Want to change the title? Use the ``/title`` command! We have solved your problem? Click the button below to archive it.
e

emellum

05/06/2022, 11:20 PM
Oh actually you know what, I think the request is coming from an "anonymous user" since I'm making it from my backend... I think I need to pass my JWT
g

garyaustin

05/06/2022, 11:22 PM
If you are ever in doubt if you have a user switch auth.uid() to auth.role() = 'anon' as a quick test.
n

Needle

05/06/2022, 11:22 PM
emellum (2022-05-06)
e

emellum

05/06/2022, 11:23 PM
That's a good tip. Thank you @garyaustin . Now I just need to figure out how to pass the JWT to the backend and then include that in the supabase client creation. I think I've seen some details about this
g

garyaustin

05/06/2022, 11:25 PM
Scattered about info. You will use .setAuth(jwt) to actually set it. https://github.com/supabase-community/supabase-auth-helpers is a good place to either get code or look at some of the issues with calling from a server.
e

emellum

05/06/2022, 11:39 PM
Just like that it's working. Thank you for the setAuth tip, that worked nicely. Although I don't understand why passing it in as an option did not work for me. It was saying:
Duplicate API Key Found
Copy code
import { createClient } from '@supabase/supabase-js'

const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL!
const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
const jwtSecret = process.env.SUPABASE_JWT_SECRET!

export const supabase = (jwt?) => {
  const options = jwt
    ? {
        headers: {
          apiKey: jwtSecret,
          Authorisation: `Bearer ${jwt}`,
        },
      }
    : {}
  return createClient(supabaseUrl, supabaseAnonKey, options)
At any rate, modifying the bottom to be:
Copy code
const supabase = createClient(supabaseUrl, supabaseAnonKey)
  const { user } = supabase.auth.setAuth(jwt)
  return supabase
Allowed things to work.