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
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
23export function SettingsAuthRouteScreen() {
24 const navigation = useNavigation();
25
26 useLayoutEffect(() => {
27 if (!hasCloudPublicConfig()) {
28 navigation.dispatch(StackActions.replace("SettingsContent"));
29 }
30 }, [navigation]);
31
32 return hasCloudPublicConfig() ? <ConfiguredSettingsAuthRouteScreen /> : null;
33}
34
35function ConfiguredSettingsAuthRouteScreen() {
36 const { isLoaded, isSignedIn } = useAuth({ treatPendingAsSignedOut: false });
37 const navigation = useNavigation();
38 const handleHostBack = useCallback(
39 () => navigation.dispatch(StackActions.popTo("SettingsContent")),
40 [navigation],
41 );
42 const hasBeenSignedIn = useRef(isSignedIn);
43 if (isSignedIn) {
44 hasBeenSignedIn.current = true;
45 }
46
47 useEffect(() => {
48 if (hasBeenSignedIn.current && isLoaded && isSignedIn === false) {
49 navigation.dispatch(StackActions.popTo("SettingsContent"));
50 }
51 }, [isLoaded, isSignedIn, navigation]);
52
53 return (
54 <View collapsable={false} className="flex-1 overflow-hidden bg-sheet">
55 {isLoaded ? (
56 hasBeenSignedIn.current ? (
57 <UserProfileView
58 customPages={USER_PROFILE_CUSTOM_PAGES}
59 isDismissible={false}
60 onHostBack={handleHostBack}
61 />
62 ) : (
63 <AuthView isDismissible={false} onHostBack={handleHostBack} />
64 )
65 ) : null}
66 </View>
67 );
68}