The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { useAuth } from "@clerk/expo"; |
| 2 | import { |
| 3 | AuthView, |
| 4 | type UserProfileCustomPage, |
| 5 | UserProfileView, |
| 6 | } from "@clerk/expo/native-components"; |
| 7 | import { useNavigation } from "@react-navigation/native"; |
| 8 | import { useEffect, useState } from "react"; |
| 9 | import { View } from "react-native"; |
| 10 | |
| 11 | import { hasCloudPublicConfig } from "../cloud/publicConfig"; |
| 12 | import { T3ConnectProfilePage } from "../cloud/T3ConnectProfilePage"; |
| 13 | |
| 14 | const 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. |
| 24 | export function SettingsAuthRouteScreen() { |
| 25 | return hasCloudPublicConfig() ? <ConfiguredSettingsAuthRouteScreen /> : null; |
| 26 | } |
| 27 | |
| 28 | function 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 | // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- pops the navigator when Clerk's auth store reports a sign-out from the profile view or Connect page |
| 40 | useEffect(() => { |
| 41 | if (hasBeenSignedIn && isLoaded && isSignedIn === false) { |
| 42 | navigation.goBack(); |
| 43 | } |
| 44 | }, [hasBeenSignedIn, isLoaded, isSignedIn, navigation]); |
| 45 | |
| 46 | return ( |
| 47 | <View collapsable={false} className="flex-1 overflow-hidden bg-sheet"> |
| 48 | {isLoaded ? ( |
| 49 | hasBeenSignedIn ? ( |
| 50 | <UserProfileView |
| 51 | customPages={USER_PROFILE_CUSTOM_PAGES} |
| 52 | isDismissible={false} |
| 53 | onHostBack={handleHostBack} |
| 54 | /> |
| 55 | ) : ( |
| 56 | <AuthView isDismissible={false} onHostBack={handleHostBack} /> |
| 57 | ) |
| 58 | ) : null} |
| 59 | </View> |
| 60 | ); |
| 61 | } |