This commit is contained in:
Jamie Brunton committed 2025-12-29 22:15:41 +00:00
1 parent 8acc43981e
commit 118dadc69a
122 files changed
+1688 -218

No files matched your search

+12 -10
View File
@@ -1,14 +1,16 @@
import "react-native-url-polyfill/auto";
import { createClient } from "@supabase/supabase-js";
import * as SecureStore from "expo-secure-store";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { Platform } from "react-native";
// In-memory storage fallback for SSR/Node.js environments
const memoryStorage: Record<string, string> = {};
// SecureStore adapter for Supabase auth
const ExpoSecureStoreAdapter = {
getItem: (key: string) => {
// AsyncStorage adapter for Supabase auth
// Note: We use AsyncStorage instead of SecureStore because Supabase JWTs
// can exceed SecureStore's 2048 byte limit
const ExpoStorageAdapter = {
getItem: async (key: string): Promise<string | null> => {
if (Platform.OS === "web") {
// Check if we're in a browser environment with localStorage
if (typeof window !== "undefined" && typeof window.localStorage !== "undefined") {
@@ -17,9 +19,9 @@ const ExpoSecureStoreAdapter = {
// Fallback for SSR/Node.js
return memoryStorage[key] ?? null;
}
return SecureStore.getItemAsync(key);
return AsyncStorage.getItem(key);
},
setItem: (key: string, value: string) => {
setItem: async (key: string, value: string): Promise<void> => {
if (Platform.OS === "web") {
if (typeof window !== "undefined" && typeof window.localStorage !== "undefined") {
window.localStorage.setItem(key, value);
@@ -29,9 +31,9 @@ const ExpoSecureStoreAdapter = {
memoryStorage[key] = value;
return;
}
return SecureStore.setItemAsync(key, value);
await AsyncStorage.setItem(key, value);
},
removeItem: (key: string) => {
removeItem: async (key: string): Promise<void> => {
if (Platform.OS === "web") {
if (typeof window !== "undefined" && typeof window.localStorage !== "undefined") {
window.localStorage.removeItem(key);
@@ -41,7 +43,7 @@ const ExpoSecureStoreAdapter = {
delete memoryStorage[key];
return;
}
return SecureStore.deleteItemAsync(key);
await AsyncStorage.removeItem(key);
},
};
@@ -53,7 +55,7 @@ console.log("DEBUG - Anon key preview:", supabaseAnonKey?.substring(0, 30) + "..
export const supabase = createClient(supabaseUrl, supabaseAnonKey, {
auth: {
storage: ExpoSecureStoreAdapter,
storage: ExpoStorageAdapter,
autoRefreshToken: true,
persistSession: true,
detectSessionInUrl: Platform.OS === "web",