diff --git a/src/app/(tabs)/index.tsx b/src/app/(tabs)/index.tsx
index 6a06c52..80c640f 100644
--- a/src/app/(tabs)/index.tsx
+++ b/src/app/(tabs)/index.tsx
@@ -1,5 +1,5 @@
import { Redirect } from 'expo-router'
export default () => {
- return
+ return
}
diff --git a/src/app/_layout.tsx b/src/app/_layout.tsx
index cf034ec..2980f76 100644
--- a/src/app/_layout.tsx
+++ b/src/app/_layout.tsx
@@ -1,9 +1,8 @@
-import auth from '@react-native-firebase/auth'
import { GoogleSignin } from '@react-native-google-signin/google-signin'
import * as Sentry from '@sentry/react-native'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { isRunningInExpoGo } from 'expo'
-import { Slot, useNavigationContainerRef, useRouter } from 'expo-router'
+import { Slot, useNavigationContainerRef, useRouter, useSegments } from 'expo-router'
import * as SplashScreen from 'expo-splash-screen'
import { useEffect } from 'react'
import { SafeAreaProvider } from 'react-native-safe-area-context'
@@ -12,6 +11,7 @@ import { NetInfoToast, Toast } from '@app/components'
import { GOOGLE_WEB_CLIENT_ID, IS_PROD, SENTRY_DEBUG, SENTRY_DSN } from '@app/env'
import { useLoadFonts } from '@app/hooks'
import { useStorageDevTools } from '@app/storage'
+import { useStore } from '@app/store'
import '@app/theme'
import '@app/translations'
@@ -37,28 +37,31 @@ const RootLayout = () => {
const ref = useNavigationContainerRef()
const { fontsFinishedLoading } = useLoadFonts()
const router = useRouter()
+ const segments = useSegments()
const queryClient = new QueryClient()
+ const user = useStore(state => state.auth.user)
+ const authRequired = segments[0] === '(tabs)'
useEffect(() => {
if (fontsFinishedLoading) {
- const unsubscribe = auth().onAuthStateChanged(user =>
- // setTimeout used to ensure that all synchronous state updates and rendering are executed first
- setTimeout(() => {
- router.replace(user ? '/(tabs)/Home' : '/(auth)/Welcome')
- }),
- )
-
SplashScreen.hideAsync()
routingInstrumentation.registerNavigationContainer(ref)
GoogleSignin.configure({
webClientId: GOOGLE_WEB_CLIENT_ID,
})
GoogleSignin.hasPlayServices()
-
- return unsubscribe
}
}, [fontsFinishedLoading])
+ useEffect(() => {
+ if (authRequired && !user) {
+ router.replace('/(auth)/Welcome')
+ }
+ if (!authRequired && user) {
+ router.replace('/(tabs)/Home')
+ }
+ }, [user, authRequired])
+
useStorageDevTools()
return (