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

SettingsAuthRouteScreen.tsx

39 lines1.2 KB

1import { useAuth } from "@clerk/expo";
2import { AuthView, UserProfileView } from "@clerk/expo/native";
3import { StackActions, useNavigation } from "@react-navigation/native";
4import { NativeStackScreenOptions } from "../../native/StackHeader";
5import { useEffect } from "react";
6import { View } from "react-native";
7​
8import { hasCloudPublicConfig } from "../cloud/publicConfig";
9​
10export function SettingsAuthRouteScreen() {
11 const navigation = useNavigation();
12​
13 useEffect(() => {
14 if (!hasCloudPublicConfig()) {
15 navigation.dispatch(StackActions.replace("Settings"));
16 }
17 }, [navigation]);
18​
19 return hasCloudPublicConfig() ? <ConfiguredSettingsAuthRouteScreen /> : null;
21​
22function ConfiguredSettingsAuthRouteScreen() {
23 const { isLoaded, isSignedIn } = useAuth({ treatPendingAsSignedOut: false });
24​
25 return (
26 <>
27 <NativeStackScreenOptions options={{ title: isSignedIn ? "Account" : "Sign in" }} />
28 <View collapsable={false} className="flex-1 overflow-hidden bg-sheet">
29 {isLoaded ? (
30 isSignedIn ? (
31 <UserProfileView isDismissible={false} />
32 ) : (
33 <AuthView isDismissible={false} />
34 )
35 ) : null}
36 </View>
37 </>
38 );