Open History to see the last commit
1import { useAuth } from "@clerk/expo";
2import {
3 AuthView,
4 type UserProfileCustomPage,
5 UserProfileView,
6} from "@clerk/expo/native-components";
7import { useNavigation } from "@react-navigation/native";
8import { useEffect, useState } from "react";
9import { View } from "react-native";
10
11import { hasCloudPublicConfig } from "../cloud/publicConfig";
12import { T3ConnectProfilePage } from "../cloud/T3ConnectProfilePage";
13
14const USER_PROFILE_CUSTOM_PAGES = [
15 {
16 path: "t3-connect",
17 label: "T3 Connect",
18 icon: "globe",
19 content: <T3ConnectProfilePage />,
20 },
21] satisfies UserProfileCustomPage[];
22
23// Without cloud config the app has no entry point here and appLinking drops the deep link.
24export function SettingsAuthRouteScreen() {
25 return hasCloudPublicConfig() ? <ConfiguredSettingsAuthRouteScreen /> : null;
26}
27
28function ConfiguredSettingsAuthRouteScreen() {
29 const { isLoaded, isSignedIn } = useAuth({ treatPendingAsSignedOut: false });
30 const navigation = useNavigation();
31 const handleHostBack = () => navigation.goBack();
32 // Once signed in, stay on the profile view so signing out pops back instead of
33 // flashing the sign-in form.
34 const [hasBeenSignedIn, setHasBeenSignedIn] = useState(isSignedIn === true);
35 if (isSignedIn && !hasBeenSignedIn) setHasBeenSignedIn(true);
36
37 // Clerk reports sign-out only through its auth store (the native profile view
38 // and the T3 Connect page can both sign out), so this follows that store.
39 useEffect(() => {
40 if (hasBeenSignedIn && isLoaded && isSignedIn === false) {
41 navigation.goBack();
42 }
43 }, [hasBeenSignedIn, isLoaded, isSignedIn, navigation]);
44
45 return (
46 <View collapsable={false} className="flex-1 overflow-hidden bg-sheet">
47 {isLoaded ? (
48 hasBeenSignedIn ? (
49 <UserProfileView
50 customPages={USER_PROFILE_CUSTOM_PAGES}
51 isDismissible={false}
52 onHostBack={handleHostBack}
53 />
54 ) : (
55 <AuthView isDismissible={false} onHostBack={handleHostBack} />
56 )
57 ) : null}
58 </View>
59 );
60}