mirror of
https://github.com/supabase/supabase.git
synced 2026-07-02 13:34:27 +08:00
* Move old functions trouble shooting to new guides
* Replace getUser, update, and switch to codeblocks
* Revert "Move old functions trouble shooting to new guides"
This reverts commit 229c581172.
* Prettier
* Add env details
* Fixes
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import { AppState, Platform } from 'react-native'
|
|
import 'react-native-url-polyfill/auto'
|
|
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
import { createClient, processLock } from '@supabase/supabase-js'
|
|
|
|
const supabaseUrl = process.env.EXPO_PUBLIC_SUPABASE_URL!
|
|
const supabaseAnonKey = process.env.EXPO_PUBLIC_SUPABASE_ANON_KEY!
|
|
|
|
export const supabase = createClient(supabaseUrl, supabaseAnonKey, {
|
|
auth: {
|
|
...(Platform.OS !== 'web' ? { storage: AsyncStorage } : {}),
|
|
autoRefreshToken: true,
|
|
persistSession: true,
|
|
detectSessionInUrl: false,
|
|
lock: processLock,
|
|
},
|
|
})
|
|
|
|
// Tells Supabase Auth to continuously refresh the session automatically
|
|
// if the app is in the foreground. When this is added, you will continue
|
|
// to receive `onAuthStateChange` events with the `TOKEN_REFRESHED` or
|
|
// `SIGNED_OUT` event if the user's session is terminated. This should
|
|
// only be registered once.
|
|
if (Platform.OS !== 'web') {
|
|
AppState.addEventListener('change', (state) => {
|
|
if (state === 'active') {
|
|
supabase.auth.startAutoRefresh()
|
|
} else {
|
|
supabase.auth.stopAutoRefresh()
|
|
}
|
|
})
|
|
}
|