feat: add zero

This commit is contained in:
Max Koon
2025-10-13 21:10:46 -04:00
parent b4d13e6a9f
commit 92d297e2c9
36 changed files with 3318 additions and 455 deletions

View File

@@ -1,21 +1,20 @@
import { DarkTheme, DefaultTheme, ThemeProvider } from '@react-navigation/native';
import { Stack } from 'expo-router';
import { StatusBar } from 'expo-status-bar';
import 'react-native-reanimated';
import { useColorScheme } from '@/hooks/use-color-scheme';
import { authClient } from '@/lib/auth-client';
import { ZeroProvider } from '@rocicorp/zero/react';
import { zero } from '@/lib/zero';
export const unstable_settings = {
anchor: '(tabs)',
};
export default function RootLayout() {
const colorScheme = useColorScheme();
const { data, isPending } = authClient.useSession();
return (
<ThemeProvider value={colorScheme === 'dark' ? DarkTheme : DefaultTheme}>
<ZeroProvider zero={zero}>
<Stack>
<Stack.Protected guard={!isPending && !!data}>
<Stack.Screen name="index" />
@@ -24,7 +23,6 @@ export default function RootLayout() {
<Stack.Screen name="auth" />
</Stack.Protected>
</Stack>
<StatusBar style="auto" />
</ThemeProvider>
</ZeroProvider>
);
}

View File

@@ -1,4 +0,0 @@
import { auth } from "@/lib/auth";
const handler = auth.handler;
export { handler as GET, handler as POST };

View File

@@ -5,6 +5,7 @@ export default function Auth() {
const onLogin = () => {
authClient.signIn.oauth2({
providerId: "koon-family",
callbackURL: "http://localhost:8081"
});
};

View File

@@ -1,18 +1,21 @@
import { ThemedText } from '@/components/themed-text';
import { SafeAreaView } from 'react-native-safe-area-context';
import { authClient } from '@/lib/auth-client';
import { Button } from 'react-native';
import { Button, Text } from 'react-native';
import { useQuery, useZero } from "@rocicorp/zero/react";
import { queries } from '@money/shared';
export default function HomeScreen() {
const { data } = authClient.useSession();
const onLogout = () => {
authClient.signOut();
}
const [transactions] = useQuery(queries.allTransactions());
return (
<SafeAreaView>
<ThemedText>Hello {data?.user.name}</ThemedText>
<Text>Hello {data?.user.name}</Text>
<Button onPress={onLogout} title="Logout" />
<Text>Transactions: {JSON.stringify(transactions, null, 4)}</Text>
</SafeAreaView>
);
}