fix(mobile): avoid duplicate Clerk auth back buttons

This commit is contained in:
Gabriel De Andrade committed 2026-07-28 20:27:42 -04:00
1 parent 8650f05f95
commit 08daccbd62
3 files changed
+41 -2

No files matched your search

@@ -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",
});
});
});
@@ -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",
};
}
@@ -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 (
<>
<NativeStackScreenOptions options={{ title: isSignedIn ? "Account" : "Sign in" }} />
<NativeStackScreenOptions
options={resolveSettingsAuthHeaderOptions({ isLoaded, isSignedIn })}
/>
<View collapsable={false} className="flex-1 overflow-hidden bg-sheet">
{isLoaded ? (
isSignedIn ? (
<UserProfileView isDismissible={false} />
) : (
<AuthView isDismissible={false} />
<AuthView isDismissible onDismiss={() => navigation.goBack()} />
)
) : null}
</View>