I’m seeing something weird with the supaBaseClient...
# javascript
m
I’m seeing something weird with the supaBaseClient sdk and it’s related to RLS. I’ve got the following policies defined on a table (see attachment) and I only get data back on initial load. If I refresh, I’m getting back an empty array. It definitely seems RLS related because when I temporarily disable RLS for that table — I get back results every time, even on refresh
g
You are probably accessing the table before supabase finishes checking and setting up the user from local storage if you are running just client code. If you have server side code involved, other things can come into play. You can use onAuthStateChange and log signin event to see if you are going out before you have a user.
m
Yeah that could very well be it.
I'm using the new
supabase-auth-helpers
Copy code
import {
  withAuthRequired,
  getUser,
  User,
} from '@supabase/supabase-auth-helpers/nextjs'
then in my
getServerSideProps
I'm doing
Copy code
export const getServerSideProps = withAuthRequired({
  redirectTo: '/sign-in',
  async getServerSideProps(ctx) {
    // Access the user object
    const { user } = await getUser(ctx)
    return { props: { user } }
  },
})
I'm getting a user back every time in my component though, so I'm not sure why this call w/ RLS is choking on me
g
My comment about if using server side stuff applies then and could be a number of things... But I don't do server side code in my project, so really not much help. If no one else comes along, ask again in a new question mentioning supabase-auth-helpers in your comment.
m
it's okay I figured out the issue. Because I'm dealing with server side context I needed to call the
supabaseServerClient(ctx)
like so
Copy code
const { data: member, error } = await supabaseServerClient(ctx)
      .from<definitions['member']>('member')
      .select('*')
      .eq('id', userId)