Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/workflows/type-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ permissions:
contents: read
pull-requests: write

permissions:
contents: read
pull-requests: write

jobs:
type-check:
name: Type Check (tsc)
Expand Down
2 changes: 1 addition & 1 deletion env.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ require('dotenv').config({
* for example: if the APP_ENV is staging, the bundle id will be com.rootstrap.staging
*/

// TODO: Replace these values with your own
// TODO: Replace these values with your own values

const BUNDLE_ID = 'com.rootstrap'; // ios bundle id
const PACKAGE = 'com.rootstrap'; // android package name
Expand Down
61 changes: 45 additions & 16 deletions src/app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { KeyboardProvider } from 'react-native-keyboard-controller';

import { APIProvider } from '@/api';
import interceptors from '@/api/common/interceptors';
import { AuthProvider } from '@/components/providers/auth';
import { hydrateAuth, loadSelectedTheme } from '@/lib';
import { AuthProvider, useAuth } from '@/components/providers/auth';
import { hydrateAuth, loadSelectedTheme, useIsFirstTime } from '@/lib';
import { useThemeConfig } from '@/lib/use-theme-config';

export { ErrorBoundary } from 'expo-router';
Expand All @@ -35,36 +35,65 @@ SplashScreen.setOptions({
fade: true,
});

export default function RootLayout() {
function GuardedStack() {
const { isAuthenticated } = useAuth();
const { t } = useTranslation();
const [isFirstTime] = useIsFirstTime();

return (
<Providers>
<Stack>
<Stack.Screen name="(app)" options={{ headerShown: false }} />
<Stack>
<Stack.Protected guard={isFirstTime}>
<Stack.Screen name="onboarding" options={{ headerShown: false }} />
<Stack.Screen name="forgot-password" />
</Stack.Protected>

<Stack.Protected guard={isAuthenticated}>
<Stack.Screen name="(app)" options={{ headerShown: false }} />
<Stack.Screen
name="update-password"
options={{
title: t('updatePassword.title'),
}}
/>
</Stack.Protected>

<Stack.Protected guard={!isAuthenticated}>
<Stack.Screen name="sign-in" options={{ headerShown: false }} />
<Stack.Screen name="sign-up" />
<Stack.Screen
name="www"
options={{
presentation: 'modal',
title: '', // Title will be overridden by the screen itself
}}
/>
</Stack>
<Stack.Screen name="forgot-password" />
</Stack.Protected>

<Stack.Screen
name="www"
options={{
presentation: 'modal',
title: '',
}}
/>
</Stack>
);
}

export default function RootLayout() {
return (
<Providers>
<RouterContent />
</Providers>
);
}

function Providers({ children }: { children: React.ReactNode }) {
function RouterContent() {
const { ready } = useAuth();

if (!ready) {
return <Stack />;
}

return <GuardedStack />;
}

function Providers({ children }: Readonly<{ children: React.ReactNode }>) {
const theme = useThemeConfig();

return (
<GestureHandlerRootView
style={styles.container}
Expand Down
6 changes: 0 additions & 6 deletions src/app/sign-in.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useRouter } from 'expo-router';
import React from 'react';
import { showMessage } from 'react-native-flash-message';

Expand All @@ -7,12 +6,7 @@ import { LoginForm, type LoginFormProps } from '@/components/login-form';
import { FocusAwareStatusBar } from '@/components/ui';

export default function Login() {
const router = useRouter();

const { mutate: login, isPending } = useLogin({
onSuccess: () => {
router.push('/');
},
onError: (error) => showMessage({ message: error.message, type: 'danger' }),
});

Expand Down
6 changes: 0 additions & 6 deletions src/app/sign-up.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useRouter } from 'expo-router';
import React from 'react';
import { showMessage } from 'react-native-flash-message';

Expand All @@ -8,12 +7,7 @@ import { SignUpForm } from '@/components/sign-up-form';
import { FocusAwareStatusBar } from '@/components/ui';

export default function SignIn() {
const router = useRouter();

const { mutate: signUp, isPending } = useSignUp({
onSuccess: () => {
router.push('/');
},
onError: (error) => showMessage({ message: error.message, type: 'danger' }),
});

Expand Down