@@ -14,8 +14,8 @@ import { KeyboardProvider } from 'react-native-keyboard-controller';
1414
1515import { APIProvider } from '@/api' ;
1616import interceptors from '@/api/common/interceptors' ;
17- import { AuthProvider } from '@/components/providers/auth' ;
18- import { hydrateAuth , loadSelectedTheme } from '@/lib' ;
17+ import { AuthProvider , useAuth } from '@/components/providers/auth' ;
18+ import { hydrateAuth , loadSelectedTheme , useIsFirstTime } from '@/lib' ;
1919import { useThemeConfig } from '@/lib/use-theme-config' ;
2020
2121export { ErrorBoundary } from 'expo-router' ;
@@ -35,36 +35,65 @@ SplashScreen.setOptions({
3535 fade : true ,
3636} ) ;
3737
38- export default function RootLayout ( ) {
38+ function GuardedStack ( ) {
39+ const { isAuthenticated } = useAuth ( ) ;
3940 const { t } = useTranslation ( ) ;
41+ const [ isFirstTime ] = useIsFirstTime ( ) ;
42+
4043 return (
41- < Providers >
42- < Stack >
43- < Stack . Screen name = "(app)" options = { { headerShown : false } } />
44+ < Stack >
45+ < Stack . Protected guard = { isFirstTime } >
4446 < Stack . Screen name = "onboarding" options = { { headerShown : false } } />
45- < Stack . Screen name = "forgot-password" />
47+ </ Stack . Protected >
48+
49+ < Stack . Protected guard = { isAuthenticated } >
50+ < Stack . Screen name = "(app)" options = { { headerShown : false } } />
4651 < Stack . Screen
4752 name = "update-password"
4853 options = { {
4954 title : t ( 'updatePassword.title' ) ,
5055 } }
5156 />
57+ </ Stack . Protected >
58+
59+ < Stack . Protected guard = { ! isAuthenticated } >
5260 < Stack . Screen name = "sign-in" options = { { headerShown : false } } />
5361 < Stack . Screen name = "sign-up" />
54- < Stack . Screen
55- name = "www"
56- options = { {
57- presentation : 'modal' ,
58- title : '' , // Title will be overridden by the screen itself
59- } }
60- />
61- </ Stack >
62+ < Stack . Screen name = "forgot-password" />
63+ </ Stack . Protected >
64+
65+ < Stack . Screen
66+ name = "www"
67+ options = { {
68+ presentation : 'modal' ,
69+ title : '' ,
70+ } }
71+ />
72+ </ Stack >
73+ ) ;
74+ }
75+
76+ export default function RootLayout ( ) {
77+ return (
78+ < Providers >
79+ < RouterContent />
6280 </ Providers >
6381 ) ;
6482}
6583
66- function Providers ( { children } : { children : React . ReactNode } ) {
84+ function RouterContent ( ) {
85+ const { ready } = useAuth ( ) ;
86+
87+ if ( ! ready ) {
88+ return < Stack /> ;
89+ }
90+
91+ return < GuardedStack /> ;
92+ }
93+
94+ function Providers ( { children } : Readonly < { children : React . ReactNode } > ) {
6795 const theme = useThemeConfig ( ) ;
96+
6897 return (
6998 < GestureHandlerRootView
7099 style = { styles . container }
0 commit comments