-
Notifications
You must be signed in to change notification settings - Fork 0
fix(mobile): lazy Supabase client to stop grey-screen crash on launch #174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,28 +1,35 @@ | ||||||||||||||||||||||||
| import 'react-native-url-polyfill/auto' | ||||||||||||||||||||||||
| import 'expo-sqlite/localStorage/install' | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| import { createClient } from '@supabase/supabase-js' | ||||||||||||||||||||||||
| import { createClient, type SupabaseClient } from '@supabase/supabase-js' | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| interface SupabaseStorageAdapter { | ||||||||||||||||||||||||
| getItem: (key: string) => string | null | ||||||||||||||||||||||||
| setItem: (key: string, value: string) => void | ||||||||||||||||||||||||
| removeItem: (key: string) => void | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const SUPABASE_URL = process.env.EXPO_PUBLIC_SUPABASE_URL | ||||||||||||||||||||||||
| const SUPABASE_PUBLISHABLE_KEY = process.env.EXPO_PUBLIC_SUPABASE_PUBLISHABLE_KEY | ||||||||||||||||||||||||
| const SUPABASE_URL = | ||||||||||||||||||||||||
| process.env.EXPO_PUBLIC_SUPABASE_URL ?? 'https://wdscxamegetmhqldqsdg.supabase.co' | ||||||||||||||||||||||||
| const SUPABASE_PUBLISHABLE_KEY = | ||||||||||||||||||||||||
| process.env.EXPO_PUBLIC_SUPABASE_PUBLISHABLE_KEY ?? | ||||||||||||||||||||||||
| 'sb_publishable_CGlL4PSxvp2Ia0SCHcathQ_iAQnmXis' | ||||||||||||||||||||||||
|
Comment on lines
+12
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This pattern is still present and still violates CLAUDE.md rule 7: The root cause is that
Suggested change
The lazy-client pattern ( |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if (!SUPABASE_URL || !SUPABASE_PUBLISHABLE_KEY) { | ||||||||||||||||||||||||
| throw new Error('Supabase config missing') | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const storage = (globalThis as typeof globalThis & { localStorage: SupabaseStorageAdapter }).localStorage | ||||||||||||||||||||||||
| let client: SupabaseClient | null = null | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| export const supabase = createClient(SUPABASE_URL, SUPABASE_PUBLISHABLE_KEY, { | ||||||||||||||||||||||||
| auth: { | ||||||||||||||||||||||||
| storage, | ||||||||||||||||||||||||
| autoRefreshToken: true, | ||||||||||||||||||||||||
| persistSession: true, | ||||||||||||||||||||||||
| detectSessionInUrl: false, | ||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||
| export function getSupabaseClient(): SupabaseClient { | ||||||||||||||||||||||||
| if (!client) { | ||||||||||||||||||||||||
| const storage = ( | ||||||||||||||||||||||||
| globalThis as typeof globalThis & { localStorage: SupabaseStorageAdapter } | ||||||||||||||||||||||||
| ).localStorage | ||||||||||||||||||||||||
| client = createClient(SUPABASE_URL, SUPABASE_PUBLISHABLE_KEY, { | ||||||||||||||||||||||||
| auth: { | ||||||||||||||||||||||||
| storage, | ||||||||||||||||||||||||
| autoRefreshToken: true, | ||||||||||||||||||||||||
| persistSession: true, | ||||||||||||||||||||||||
| detectSessionInUrl: false, | ||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| return client | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CLAUDE.md rule 7 violation — hardcoded fallbacks mask a config bug.
process.env.X ?? 'hardcoded-default'is explicitly banned by the rootCLAUDE.mdworkaround list. If the build ever points at a different Supabase project these values will silently be wrong instead of erroring loudly.The root-cause fix is to ensure
EXPO_PUBLIC_SUPABASE_URLandEXPO_PUBLIC_SUPABASE_PUBLISHABLE_KEYare present in every build context (.env, EAS Build environment variables, orapp.jsonextra), then restore the hard throw:and inside
getSupabaseClient(), beforecreateClient: