|
1 | 1 | import { createClient } from "@supabase/supabase-js"; |
2 | 2 |
|
3 | | -const supabaseUrl = import.meta.env.VITE_SUPABASE_URL; |
4 | | -const supabaseKey = import.meta.env.VITE_SUPABASE_ANON_KEY; |
| 3 | +const supabaseUrl = String(import.meta.env.VITE_SUPABASE_URL || "").trim(); |
| 4 | +const supabaseKey = String(import.meta.env.VITE_SUPABASE_ANON_KEY || "").trim(); |
5 | 5 |
|
6 | | -export const supabase = createClient(supabaseUrl, supabaseKey); |
| 6 | +export const SUPABASE_UNCONFIGURED_MESSAGE = |
| 7 | + "Cloud login is unavailable because Supabase is not configured."; |
| 8 | + |
| 9 | +export const isSupabaseConfigured = Boolean(supabaseUrl && supabaseKey); |
| 10 | + |
| 11 | +export function assertSupabaseConfigured() { |
| 12 | + if (!isSupabaseConfigured) { |
| 13 | + throw new Error(SUPABASE_UNCONFIGURED_MESSAGE); |
| 14 | + } |
| 15 | +} |
| 16 | + |
| 17 | +function createUnavailableSupabaseClient() { |
| 18 | + const rejectUnavailable = async function () { |
| 19 | + throw new Error(SUPABASE_UNCONFIGURED_MESSAGE); |
| 20 | + }; |
| 21 | + |
| 22 | + const throwUnavailable = function () { |
| 23 | + throw new Error(SUPABASE_UNCONFIGURED_MESSAGE); |
| 24 | + }; |
| 25 | + |
| 26 | + return { |
| 27 | + auth: { |
| 28 | + getUser: rejectUnavailable, |
| 29 | + signInWithPassword: rejectUnavailable, |
| 30 | + signUp: rejectUnavailable, |
| 31 | + signOut: rejectUnavailable, |
| 32 | + onAuthStateChange: function () { |
| 33 | + return { |
| 34 | + data: { |
| 35 | + subscription: { |
| 36 | + unsubscribe: function () {}, |
| 37 | + }, |
| 38 | + }, |
| 39 | + }; |
| 40 | + }, |
| 41 | + }, |
| 42 | + from: throwUnavailable, |
| 43 | + storage: { |
| 44 | + from: throwUnavailable, |
| 45 | + }, |
| 46 | + }; |
| 47 | +} |
| 48 | + |
| 49 | +export const supabase = isSupabaseConfigured |
| 50 | + ? createClient(supabaseUrl, supabaseKey) |
| 51 | + : createUnavailableSupabaseClient(); |
0 commit comments