advance
This commit is contained in:
28
lib/supabase/config.ts
Normal file
28
lib/supabase/config.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
const isValidHttpUrl = (value: string): boolean => {
|
||||
try {
|
||||
const parsed = new URL(value);
|
||||
return parsed.protocol === "http:" || parsed.protocol === "https:";
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
export type SupabasePublicConfig = {
|
||||
url: string;
|
||||
anonKey: string;
|
||||
};
|
||||
|
||||
export const readSupabasePublicConfig = (): SupabasePublicConfig | null => {
|
||||
const url = process.env.NEXT_PUBLIC_SUPABASE_URL?.trim();
|
||||
const anonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY?.trim();
|
||||
|
||||
if (!url || !anonKey) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!isValidHttpUrl(url)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return { url, anonKey };
|
||||
};
|
||||
Reference in New Issue
Block a user