Skip to content

Commit

Permalink
fix(mobile): fix local auth guard cause router crashes (#253)
Browse files Browse the repository at this point in the history
Resolves #251
  • Loading branch information
bkdev98 committed Sep 2, 2024
1 parent 7dfac0b commit 0593310
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 128 deletions.
256 changes: 129 additions & 127 deletions apps/mobile/app/(app)/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useLingui } from '@lingui/react'
import { Link, Redirect, SplashScreen, Stack } from 'expo-router'
import { PlusIcon } from 'lucide-react-native'
import { useEffect } from 'react'
import { View } from 'react-native'

export default function AuthenticatedLayout() {
const { isLoaded, isSignedIn } = useUser()
Expand All @@ -35,134 +36,135 @@ export default function AuthenticatedLayout() {
return <Redirect href={'/onboarding/step-one'} />
}

if (shouldAuthLocal) {
return <AuthLocal onAuthenticated={() => setShouldAuthLocal(false)} />
}

return (
<Stack
screenOptions={{
headerShown: true,
headerBackTitleVisible: false,
headerTintColor: theme[colorScheme ?? 'light'].primary,
headerShadowVisible: false,
headerTitleStyle: {
fontFamily: 'Inter Medium',
fontSize: 16,
color: theme[colorScheme ?? 'light'].primary,
},
headerStyle: {
backgroundColor: theme[colorScheme ?? 'light'].background,
},
headerLeft: () => <BackButton />,
}}
>
<Stack.Screen
name="(tabs)"
options={{
headerShown: false,
}}
/>
<Stack.Screen
name="transaction/new-record"
options={{
presentation: 'modal',
headerTitle: '',
// headerShown: false,
}}
/>
<Stack.Screen
name="review-transactions"
options={{
headerTitle: t(i18n)`Review transactions`,
}}
/>
<Stack.Screen
name="transaction/[transactionId]"
options={{
presentation: 'modal',
headerShown: false,
}}
/>
<Stack.Screen
name="language"
options={{
presentation: 'modal',
headerTitle: t(i18n)`Language`,
}}
/>
<Stack.Screen
name="profile"
options={{
presentation: 'modal',
headerTitle: t(i18n)`Profile`,
}}
/>
<Stack.Screen
name="appearance"
options={{ headerTitle: t(i18n)`Appearance` }}
/>
<Stack.Screen
name="wallet/accounts"
options={{
headerTitle: t(i18n)`Wallet accounts`,
headerRight: () => (
<Link href="/wallet/new-account" asChild>
<Button size="icon" variant="ghost">
<PlusIcon className="size-6 text-primary" />
</Button>
</Link>
),
}}
/>
<Stack.Screen
name="wallet/new-account"
options={{
presentation: 'modal',
headerTitle: t(i18n)`New account`,
}}
/>
<Stack.Screen
name="wallet/[walletId]"
options={{
presentation: 'modal',
headerTitle: t(i18n)`Edit account`,
}}
/>
<Stack.Screen
name="category/index"
options={{
headerTitle: t(i18n)`Categories`,
headerRight: () => (
<Link href="/category/new-category" asChild>
<Button size="icon" variant="ghost">
<PlusIcon className="size-6 text-primary" />
</Button>
</Link>
),
}}
/>
<Stack.Screen
name="category/new-category"
options={{
presentation: 'modal',
headerTitle: t(i18n)`New category`,
}}
/>
<Stack.Screen
name="category/[categoryId]"
options={{
presentation: 'modal',
headerTitle: t(i18n)`Edit category`,
}}
/>
<Stack.Screen
name="budget/new-budget"
options={{
presentation: 'modal',
headerTitle: t(i18n)`New budget`,
<View className="flex-1">
{shouldAuthLocal && (
<AuthLocal onAuthenticated={() => setShouldAuthLocal(false)} />
)}
<Stack
screenOptions={{
headerShown: true,
headerBackTitleVisible: false,
headerTintColor: theme[colorScheme ?? 'light'].primary,
headerShadowVisible: false,
headerTitleStyle: {
fontFamily: 'Inter Medium',
fontSize: 16,
color: theme[colorScheme ?? 'light'].primary,
},
headerStyle: {
backgroundColor: theme[colorScheme ?? 'light'].background,
},
headerLeft: () => <BackButton />,
}}
/>
</Stack>
>
<Stack.Screen
name="(tabs)"
options={{
headerShown: false,
}}
/>
<Stack.Screen
name="transaction/new-record"
options={{
presentation: 'modal',
headerTitle: '',
// headerShown: false,
}}
/>
<Stack.Screen
name="review-transactions"
options={{
headerTitle: t(i18n)`Review transactions`,
}}
/>
<Stack.Screen
name="transaction/[transactionId]"
options={{
presentation: 'modal',
headerShown: false,
}}
/>
<Stack.Screen
name="language"
options={{
presentation: 'modal',
headerTitle: t(i18n)`Language`,
}}
/>
<Stack.Screen
name="profile"
options={{
presentation: 'modal',
headerTitle: t(i18n)`Profile`,
}}
/>
<Stack.Screen
name="appearance"
options={{ headerTitle: t(i18n)`Appearance` }}
/>
<Stack.Screen
name="wallet/accounts"
options={{
headerTitle: t(i18n)`Wallet accounts`,
headerRight: () => (
<Link href="/wallet/new-account" asChild>
<Button size="icon" variant="ghost">
<PlusIcon className="size-6 text-primary" />
</Button>
</Link>
),
}}
/>
<Stack.Screen
name="wallet/new-account"
options={{
presentation: 'modal',
headerTitle: t(i18n)`New account`,
}}
/>
<Stack.Screen
name="wallet/[walletId]"
options={{
presentation: 'modal',
headerTitle: t(i18n)`Edit account`,
}}
/>
<Stack.Screen
name="category/index"
options={{
headerTitle: t(i18n)`Categories`,
headerRight: () => (
<Link href="/category/new-category" asChild>
<Button size="icon" variant="ghost">
<PlusIcon className="size-6 text-primary" />
</Button>
</Link>
),
}}
/>
<Stack.Screen
name="category/new-category"
options={{
presentation: 'modal',
headerTitle: t(i18n)`New category`,
}}
/>
<Stack.Screen
name="category/[categoryId]"
options={{
presentation: 'modal',
headerTitle: t(i18n)`Edit category`,
}}
/>
<Stack.Screen
name="budget/new-budget"
options={{
presentation: 'modal',
headerTitle: t(i18n)`New budget`,
}}
/>
</Stack>
</View>
)
}
2 changes: 1 addition & 1 deletion apps/mobile/components/auth/auth-local.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function AuthLocal({ onAuthenticated }: AuthLocalProps) {
}, [])

return (
<SafeAreaView className="flex-1 items-center justify-center gap-4 bg-muted">
<SafeAreaView className="absolute top-0 right-0 bottom-0 left-0 z-50 flex-1 items-center justify-center gap-4 bg-muted">
<LockKeyholeIcon className="size-12 text-primary" />
<Text className="mx-8">{t(
i18n,
Expand Down

0 comments on commit 0593310

Please sign in to comment.