-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent white screen of ☠️ (#150)
* fix: onboarding state * fix: prevent image being cut off * fix: prevent image cutoff on unlock screen
- Loading branch information
Showing
4 changed files
with
23 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,32 @@ | ||
import { Redirect, Stack } from 'expo-router'; | ||
import { useSession } from '~/hooks/useSession'; | ||
import { useHandleLinking } from '~/hooks/useHandleLinking'; | ||
import { secureStorage } from '~/lib/secureStorage'; | ||
import { hasOnboardedKey } from '~/lib/state/appStore'; | ||
import { useMemo } from 'react'; // Add useMemo | ||
|
||
export default function AppLayout() { | ||
const { hasSession } = useSession(); | ||
useHandleLinking(); | ||
|
||
// Only require authentication within the (app) group's layout as users | ||
// need to be able to access the (auth) group and sign in again. | ||
// Memoize the onboarded status to prevent unnecessary reads from storage | ||
const isOnboarded = useMemo(() => { | ||
return secureStorage.getItem(hasOnboardedKey); | ||
}, []); | ||
|
||
// Don't render while the onboarding state is loaded | ||
if (isOnboarded === null) { | ||
return null; | ||
} | ||
|
||
if (!isOnboarded) { | ||
return <Redirect href="/onboarding" />; | ||
} | ||
|
||
if (!hasSession) { | ||
console.log("Not authenticated, redirecting to /unlock") | ||
// On web, static rendering will stop here as the user is not authenticated | ||
// in the headless Node process that the pages are rendered in. | ||
return <Redirect href="/unlock" />; | ||
} | ||
|
||
// This layout can be deferred because it's not the root layout. | ||
return <Stack />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters