Next JS Service Client

I wanted to create Service Role client in NextJS app following how regular client is being created, I only replaced Anon key with Service. This doesn't seem to work, thought it's because of cookies being set but seems these are necessary. Any help?

export const createServiceClient = () => {
  const cookieStore = cookies();

  return createServerClient<Database>(
    env.NEXT_PUBLIC_SUPABASE_URL!,
    env.SUPABASE_SERVICE_ACCOUNT_KEY!,
    {
      cookies: {
        getAll() {
          return cookieStore.getAll();
        },
        setAll(cookiesToSet) {
          try {
            cookiesToSet.forEach(({ name, value, options }) => {
              cookieStore.set(name, value, options);
            });
          } catch (error) {
            // The `set` method was called from a Server Component.
            // This can be ignored if you have middleware refreshing
            // user sessions.
          }
        },
      },
    },
  );
};
Was this page helpful?