import { useAuth } from "@clerk/clerk-expo"; import { Redirect } from "expo-router"; import { useEffect, useState } from "react"; import { ActivityIndicator, View } from "react-native"; import { fetchAPI } from "@/lib/fetch"; const App = () => { const { isSignedIn, userId } = useAuth(); const [role, setRole] = useState(undefined); useEffect(() => { if (!isSignedIn || !userId) return; fetchAPI(`/(api)/user?clerkId=${userId}`) .then((res) => setRole(res?.data?.role ?? null)) .catch(() => setRole(null)); }, [isSignedIn, userId]); if (!isSignedIn) return ; // Still loading the user's role from the database. if (role === undefined) { return ( ); } if (role === "driver") return ; if (role === "rider") return ; // Signed in but no role chosen yet. return ; }; export default App;