© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•3y ago•
4 replies
WreckNoFear

Service role not bypassing RLS

I'm creating a SupabaseServerClient using the @supabase/ssr package, it looks like this:

export default async function createSupabaseServerClient() {
  const cookieStore = cookies();
  return createServerClient(
    process.env.NEXT_PUBLIC_SUPABASE_URL!,
    process.env.SUPABASE_SERVICE_ROLE_KEY!,
    {
      cookies: {
        get(name: string) {
          return cookieStore.get(name)?.value;
        },

        set(name: string, value: string, options: CookieOptions) {
          cookieStore.set({ name, value, ...options });
        },

        remove(name: string, options: CookieOptions) {
          cookieStore.set({ name, value: "", ...options });
        },
      },
    }
  );
}
export default async function createSupabaseServerClient() {
  const cookieStore = cookies();
  return createServerClient(
    process.env.NEXT_PUBLIC_SUPABASE_URL!,
    process.env.SUPABASE_SERVICE_ROLE_KEY!,
    {
      cookies: {
        get(name: string) {
          return cookieStore.get(name)?.value;
        },

        set(name: string, value: string, options: CookieOptions) {
          cookieStore.set({ name, value, ...options });
        },

        remove(name: string, options: CookieOptions) {
          cookieStore.set({ name, value: "", ...options });
        },
      },
    }
  );
}


This client is used in my Auth callback route to fetch user data, determining if the user is new or not.

If I disable RLS on the users table, it returns the expected result.
If I enable RLS on the users table, it returns a blank result.
The users table has no RLS policies.

Why is this?

I might be misunderstanding something, but I thought the Service Key is meant to bypass RLS. 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

Supabase service_role_key not bypassing RLS
SupabaseSSupabase / help-and-questions
4mo ago
RLS Connection Error with Next.js + Prisma (service_role)
SupabaseSSupabase / help-and-questions
7mo ago
Not writing to table (RLS disabled; using .env with service_role secret key to authorize)
SupabaseSSupabase / help-and-questions
3y ago
Old/incorrect data fetching when using service role key to bypass RLS
SupabaseSSupabase / help-and-questions
3y ago