import { useState } from 'react' import { ActivityIndicator, Pressable, StyleSheet, Text, View } from 'react-native' import Constants from 'expo-constants' import { StatusBar } from 'expo-status-bar' import { SafeAreaProvider, SafeAreaView } from 'react-native-safe-area-context' import { createDeepSpaceExpoClient, DeepSpaceNativeProvider, RecordProvider, RecordScope, useDeepSpace, useUser, type CollectionSchema, } from 'deepspace/native' const { appId, baseUrl } = Constants.expoConfig?.extra?.deepspace as { appId: string baseUrl: string } /** One client for the whole app. Sign-in returns through ://auth/callback. */ const deepSpace = createDeepSpaceExpoClient({ baseUrl }) /** * The collections this screen reads. Pass the same array the Worker uses, for * example `import { schemas } from '../src/schemas'`, once the app has its own. */ const schemas: CollectionSchema[] = [] export default function App() { return ( ) } function Root() { const { isLoaded, isSignedIn } = useDeepSpace() if (!isLoaded) return if (!isSignedIn) return return ( ) } function SignIn() { const { signIn } = useDeepSpace() const [busy, setBusy] = useState(false) const [error, setError] = useState(null) const start = async () => { setBusy(true) setError(null) try { await signIn('google') } catch (caught) { // Closing the sheet is not an error. if ((caught as { code?: string }).code !== 'sign_in_cancelled') { setError(caught instanceof Error ? caught.message : 'Sign-in failed') } } finally { setBusy(false) } } return ( {Constants.expoConfig?.name} {error ? {error} : null} {busy ? ( ) : ( Continue with Google )} ) } function Home() { const { signOut } = useDeepSpace() const { user } = useUser() return ( {user?.name || 'Signed in'} {user?.email ? {user.email} : null} void signOut()} style={styles.button}> Sign out ) } const styles = StyleSheet.create({ screen: { flex: 1, backgroundColor: '#FFFFFF' }, centered: { alignItems: 'center', justifyContent: 'center', gap: 16, padding: 24 }, title: { fontSize: 28, fontWeight: '700', color: '#111827' }, muted: { fontSize: 15, color: '#6B7280' }, error: { color: '#DC2626', textAlign: 'center' }, button: { minHeight: 48, minWidth: 240, borderRadius: 8, backgroundColor: '#111827', alignItems: 'center', justifyContent: 'center', paddingHorizontal: 20, }, buttonText: { color: '#FFFFFF', fontSize: 17, fontWeight: '600' }, })