Β© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabaseβ€’4y agoβ€’
8 replies
Smyrii

RLS Policy not working with JWT (Auth0)

Hello all,
I'm having issues getting RLS working when sending a JWT to Supabase. I'm signing the JWT with he Supabase signing secret and sending the payload as shown below:
  const payload = {
    userId: session.user.sub,
    exp: Math.floor(Date.now() / 1000) + 60 * 60,
  };

  session.user.accessToken = jwt.sign(
    payload,
    process.env.SUPABASE_SIGNING_SECRET
  );
  const payload = {
    userId: session.user.sub,
    exp: Math.floor(Date.now() / 1000) + 60 * 60,
  };

  session.user.accessToken = jwt.sign(
    payload,
    process.env.SUPABASE_SIGNING_SECRET
  );


I'm sending the JWT (access token) when trying to get table data
 async getServerSideProps({ req, res }) {
    const {
      user: { accessToken },
    } = await getSession(req, res);

    const supabase = getSupabase(accessToken);

    const { data: notes } = await supabase.from("Notes").select("*");
    return {
      props: { notes },
    };
  },
 async getServerSideProps({ req, res }) {
    const {
      user: { accessToken },
    } = await getSession(req, res);

    const supabase = getSupabase(accessToken);

    const { data: notes } = await supabase.from("Notes").select("*");
    return {
      props: { notes },
    };
  },

But even when there user_id should match and return some results it does not. Here is my SQL below:
create or replace function auth.user_id() returns text as $$
  select nullif(current_setting('request.jwt.claims', true)::json->>'userId', '')::text;
$$ language sql stable;
create or replace function auth.user_id() returns text as $$
  select nullif(current_setting('request.jwt.claims', true)::json->>'userId', '')::text;
$$ language sql stable;

and my select policy
(user_id() = user_id)
(user_id() = user_id)


Any idea's on why this won't work? Thanks!
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

RLS policy with join not working
SupabaseSSupabase / help-and-questions
4y ago
RLS policy 'in' not working
SupabaseSSupabase / help-and-questions
4y ago
Realtime not working with Custom Jwt with RLS
SupabaseSSupabase / help-and-questions
3mo ago
RLS Policy
SupabaseSSupabase / help-and-questions
4mo ago