44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
import { NativeModules, Platform } from 'react-native'
|
|
|
|
interface E2eRuntimeCandidate {
|
|
e2eTestBuild?: unknown
|
|
supabaseUrlOverride?: unknown
|
|
supabaseAnonKeyOverride?: unknown
|
|
}
|
|
|
|
export function resolveMobileE2eSupabaseOverride(
|
|
candidate: E2eRuntimeCandidate | undefined,
|
|
platform: string,
|
|
): { url: string; anonKey: string } | null {
|
|
const url = typeof candidate?.supabaseUrlOverride === 'string'
|
|
? candidate.supabaseUrlOverride
|
|
: ''
|
|
const anonKey = typeof candidate?.supabaseAnonKeyOverride === 'string'
|
|
? candidate.supabaseAnonKeyOverride
|
|
: ''
|
|
if (url === '' && anonKey === '') return null
|
|
|
|
if (
|
|
platform !== 'android'
|
|
|| candidate?.e2eTestBuild !== true
|
|
|| url !== 'http://10.0.2.2:55321'
|
|
|| !/^sb_publishable_[A-Za-z0-9_-]{20,}$/.test(anonKey)
|
|
) {
|
|
throw new Error('mobile_e2e_supabase_override_invalid')
|
|
}
|
|
|
|
return { url, anonKey }
|
|
}
|
|
|
|
const override = resolveMobileE2eSupabaseOverride(
|
|
NativeModules.D3ROConfig as E2eRuntimeCandidate | undefined,
|
|
Platform.OS,
|
|
)
|
|
|
|
if (override !== null) {
|
|
;(
|
|
globalThis as typeof globalThis & {
|
|
__D3RO_MOBILE_E2E_SUPABASE__?: { url: string; anonKey: string }
|
|
}
|
|
).__D3RO_MOBILE_E2E_SUPABASE__ = override
|
|
}
|