© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•3mo ago•
19 replies
mnlcpc

Best practice for implementing subdomain availability check with RLS in production

Hi everyone,

I'm implementing a subdomain availability checker for a multi-tenant SaaS where users can claim custom subdomains (e.g.,
customsubdomain.website.com
customsubdomain.website.com
). I need to verify that a subdomain hasn't been taken before allowing a user to claim it.

What I'm trying to achieve:
- Check subdomain availability before user registration/onboarding
- Ensure the check is secure and can't be bypassed
- Have it work consistently in both local and production environments

Current implementation and issue:
I've implemented a solution using the Supabase service role key (secret API key) to bypass RLS for the availability check. This works perfectly in local development, but fails in production with the following error:
[SUBDOMAIN_VALIDATION] RPC error: {
  code: 'PGRST002',
  details: null,
  hint: null,
  message: 'Could not query the database for the schema cache. Retrying.'
}
[SUBDOMAIN_VALIDATION] RPC error: {
  code: 'PGRST002',
  details: null,
  hint: null,
  message: 'Could not query the database for the schema cache. Retrying.'
}


Environment details:
- Framework: Next.js 16 , App Router
- Platform: Web
- Supabase JS version: @supabase/ssr: ^0.7.0, @supabase/supabase-js: ^2.80.0,
- Deployed on Vercel

Questions:
What's the current best practice for implementing subdomain availability checks with Supabase?
Should I be using RPC functions, Edge Functions, or a different approach?
Is using the service role key for this use case appropriate, or is there a better pattern?
Why might this PGRST002 error occur only in production?

Any guidance on the recommended architecture for this common multi-tenant pattern would be greatly appreciated. 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
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Best Practice for Storage RLS
SupabaseSSupabase / help-and-questions
4y ago
Best Practice for dev database
SupabaseSSupabase / help-and-questions
6mo ago
Help with Implementing Supabase RLS Policy for Specific Field Update
SupabaseSSupabase / help-and-questions
3y ago
RLS Condition check
SupabaseSSupabase / help-and-questions
4y ago