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 { StackActions, useNavigation } from "@react-navigation/native";
8import { useCallback, useEffect, useLayoutEffect, useRef } from "react";
9import { View } from "react-native";
10
11import { hasCloudPublicConfig } from "../cloud/publicConfig";
12import { T3ConnectProfilePage } from "../cloud/T3ConnectProfilePage";
13
14// Custom rows in Clerk's native profile. Mirrors the web UserButton pages.
15const USER_PROFILE_CUSTOM_PAGES = [
16 {
17 path: "t3-connect",
18 label: "T3 Connect",
19 icon: "globe",
20 content: <T3ConnectProfilePage />,
21 },
22] satisfies UserProfileCustomPage[];
23
24export function SettingsAuthRouteScreen() {
25 const navigation = useNavigation();
26
27 useLayoutEffect(() => {
28 if (!hasCloudPublicConfig()) {
29 navigation.dispatch(StackActions.replace("SettingsContent"));
30 }
31 }, [navigation]);
32
33 return hasCloudPublicConfig() ? <ConfiguredSettingsAuthRouteScreen /> : null;
34}
35
36function ConfiguredSettingsAuthRouteScreen() {
37 const { isLoaded, isSignedIn } = useAuth({ treatPendingAsSignedOut: false });
38 const navigation = useNavigation();
39 const handleHostBack = useCallback(
40 () => navigation.dispatch(StackActions.popTo("SettingsContent")),
41 [navigation],
42 );
43 const hasBeenSignedIn = useRef(isSignedIn);
44 if (isSignedIn) {
45 hasBeenSignedIn.current = true;
46 }
47
48 useEffect(() => {
49 if (hasBeenSignedIn.current && isLoaded && isSignedIn === false) {
50 navigation.dispatch(StackActions.popTo("SettingsContent"));
51 }
52 }, [isLoaded, isSignedIn, navigation]);
53
54 return (
55 <View collapsable={false} className="flex-1 overflow-hidden bg-sheet">
56 {isLoaded ? (
57 hasBeenSignedIn.current ? (
58 <UserProfileView
59 customPages={USER_PROFILE_CUSTOM_PAGES}
60 isDismissible={false}
61 onHostBack={handleHostBack}
62 />
63 ) : (
64 <AuthView isDismissible={false} onHostBack={handleHostBack} />
65 )
66 ) : null}
67 </View>
68 );
69}