Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

SettingsAuthRouteScreen.tsx

50 lines1.6 KB

1import { useAuth } from "@clerk/expo";
2import { AuthView, UserProfileView } from "@clerk/expo/native";
3import { StackActions, useNavigation } from "@react-navigation/native";
4import { useCallback, useEffect, useLayoutEffect, useRef } from "react";
5import { View } from "react-native";
6​
7import { hasCloudPublicConfig } from "../cloud/publicConfig";
8​
9export function SettingsAuthRouteScreen() {
10 const navigation = useNavigation();
11​
12 useLayoutEffect(() => {
13 if (!hasCloudPublicConfig()) {
14 navigation.dispatch(StackActions.replace("SettingsContent"));
15 }
16 }, [navigation]);
17​
18 return hasCloudPublicConfig() ? <ConfiguredSettingsAuthRouteScreen /> : null;
20​
21function ConfiguredSettingsAuthRouteScreen() {
22 const { isLoaded, isSignedIn } = useAuth({ treatPendingAsSignedOut: false });
23 const navigation = useNavigation();
24 const handleHostBack = useCallback(
25 () => navigation.dispatch(StackActions.popTo("SettingsContent")),
26 [navigation],
27 );
28 const hasBeenSignedIn = useRef(isSignedIn);
29 if (isSignedIn) {
30 hasBeenSignedIn.current = true;
31 }
32​
33 useEffect(() => {
34 if (hasBeenSignedIn.current && isLoaded && isSignedIn === false) {
35 navigation.dispatch(StackActions.popTo("SettingsContent"));
36 }
37 }, [isLoaded, isSignedIn, navigation]);
38​
39 return (
40 <View collapsable={false} className="flex-1 overflow-hidden bg-sheet">
41 {isLoaded ? (
42 hasBeenSignedIn.current ? (
43 <UserProfileView isDismissible={false} onHostBack={handleHostBack} />
44 ) : (
45 <AuthView isDismissible={false} onHostBack={handleHostBack} />
46 )
47 ) : null}
48 </View>
49 );