extractProjectRef static method
- String url
Extracts the project ref from a Supabase URL.
Supabase project URLs are always of the form
https://<ref>.supabase.co (optionally followed by a path). The ref is
the first subdomain. Returns null on any input that does not match —
wrong scheme, no subdomain, non-supabase.co host, or malformed URL.
Used by SupabaseProvisioner to build the Management API URL and by the setup screen's "Open SQL Editor" deep link.
Implementation
static String? extractProjectRef(String url) {
final trimmed = url.trim();
if (trimmed.isEmpty) return null;
final Uri parsed;
try {
parsed = Uri.parse(trimmed);
} on FormatException {
return null;
}
if (parsed.scheme != 'https') return null;
final host = parsed.host;
if (host.isEmpty) return null;
if (!host.endsWith('.supabase.co')) return null;
final ref = host.substring(0, host.length - '.supabase.co'.length);
// Reject if there is no subdomain, or the subdomain contains a dot
// (e.g. `api.supabase.co` — project refs are a single label).
if (ref.isEmpty || ref.contains('.')) return null;
return ref;
}