File size: 952 Bytes
f566598
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { createClient } from '@supabase/supabase-js';

const supabaseUrl = import.meta.env.VITE_SUPABASE_URL;
const supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY;

export const supabase = supabaseUrl && supabaseAnonKey
  ? createClient(supabaseUrl, supabaseAnonKey)
  : null;

export const isSupabaseConfigured = () => {
  return !!supabase;
};

/** Project ref derived from VITE_SUPABASE_URL (for status text + links). */
export const supabaseProjectRef = (): string => {
  const url = import.meta.env.VITE_SUPABASE_URL as string | undefined;
  const m = url?.match(/^https:\/\/([a-z0-9-]+)\.supabase\.co/i);
  return m ? m[1] : "unconfigured";
};

/** Deep link to the configured project (or the dashboard when unset). */
export const supabaseDashboardUrl = (): string => {
  const ref = supabaseProjectRef();
  return ref === "unconfigured"
    ? "https://supabase.com/dashboard"
    : `https://supabase.com/dashboard/project/${ref}`;
};