diff --git a/apps/mobile/src/features/settings/SettingsAuthRouteScreen.logic.test.ts b/apps/mobile/src/features/settings/SettingsAuthRouteScreen.logic.test.ts new file mode 100644 index 00000000000..17d954a6511 --- /dev/null +++ b/apps/mobile/src/features/settings/SettingsAuthRouteScreen.logic.test.ts @@ -0,0 +1,26 @@ +import { describe, expect, it } from "vite-plus/test"; + +import { resolveSettingsAuthHeaderOptions } from "./SettingsAuthRouteScreen.logic"; + +describe("resolveSettingsAuthHeaderOptions", () => { + it("keeps the native header while Clerk restores the session", () => { + expect(resolveSettingsAuthHeaderOptions({ isLoaded: false, isSignedIn: undefined })).toEqual({ + headerShown: true, + title: "Sign in", + }); + }); + + it("lets Clerk own navigation during authentication", () => { + expect(resolveSettingsAuthHeaderOptions({ isLoaded: true, isSignedIn: false })).toEqual({ + headerShown: false, + title: "Sign in", + }); + }); + + it("restores the native header for the account screen", () => { + expect(resolveSettingsAuthHeaderOptions({ isLoaded: true, isSignedIn: true })).toEqual({ + headerShown: true, + title: "Account", + }); + }); +}); diff --git a/apps/mobile/src/features/settings/SettingsAuthRouteScreen.logic.ts b/apps/mobile/src/features/settings/SettingsAuthRouteScreen.logic.ts new file mode 100644 index 00000000000..ba8f6885024 --- /dev/null +++ b/apps/mobile/src/features/settings/SettingsAuthRouteScreen.logic.ts @@ -0,0 +1,9 @@ +export function resolveSettingsAuthHeaderOptions(input: { + readonly isLoaded: boolean; + readonly isSignedIn: boolean | undefined; +}) { + return { + headerShown: !input.isLoaded || input.isSignedIn === true, + title: input.isSignedIn ? "Account" : "Sign in", + }; +} diff --git a/apps/mobile/src/features/settings/SettingsAuthRouteScreen.tsx b/apps/mobile/src/features/settings/SettingsAuthRouteScreen.tsx index f6f92f5fc84..18f1831714f 100644 --- a/apps/mobile/src/features/settings/SettingsAuthRouteScreen.tsx +++ b/apps/mobile/src/features/settings/SettingsAuthRouteScreen.tsx @@ -6,6 +6,7 @@ import { useEffect } from "react"; import { View } from "react-native"; import { hasCloudPublicConfig } from "../cloud/publicConfig"; +import { resolveSettingsAuthHeaderOptions } from "./SettingsAuthRouteScreen.logic"; export function SettingsAuthRouteScreen() { const navigation = useNavigation(); @@ -21,16 +22,19 @@ export function SettingsAuthRouteScreen() { function ConfiguredSettingsAuthRouteScreen() { const { isLoaded, isSignedIn } = useAuth({ treatPendingAsSignedOut: false }); + const navigation = useNavigation(); return ( <> - + {isLoaded ? ( isSignedIn ? ( ) : ( - + navigation.goBack()} /> ) ) : null}