© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•2mo ago•
3 replies
Aron

How to enforce RLS when accessing data via supabase-js?

RLS🟡javascript
I need to access my supabase db in behalf of a user in my middleware backend. I've got RLS set up (only the auth.user can access his rows) and I've got a valid jwt_token from my client, where the user is logged in.

Is the follwing approache using supabase-js the correct way to do this?

const supabase = createClient( supabaseUrl, anonKey, {
    global: { 
      headers: {
        Authorization: `Bearer ${user_jwt_token}`
        }
      }  
  });
const supabase = createClient( supabaseUrl, anonKey, {
    global: { 
      headers: {
        Authorization: `Bearer ${user_jwt_token}`
        }
      }  
  });


Apparently, I can pass the token via headers and supabase will give access to the data according to this token.

The anonKey is like a user token without actual user reference. Therefore, it will only be able to access 'unprotected' records?
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

Supabase RLS accessing user's email.
SupabaseSSupabase / help-and-questions
4y ago
Supabase RLS
SupabaseSSupabase / help-and-questions
3w ago
How difficult is it to enforce data residency using Supabase self-hosting?
SupabaseSSupabase / help-and-questions
5mo ago
Issue accessing Supabase dashboard via GitHub login
SupabaseSSupabase / help-and-questions
4w ago