Add rider/driver role selection after sign-up

- users.role column (+ migration in seed script)
- /(api)/user: GET role by clerkId, PATCH to set role
- Role selection screen; drivers get placeholder driver-home
- Root index routes by role; hardened location handling on home
This commit is contained in:
Krikorios
2026-08-22 16:13:59 +03:00
parent fdc1664cce
commit fbe92c9d16
9 changed files with 243 additions and 19 deletions
+29 -3
View File
@@ -1,12 +1,38 @@
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 } = useAuth();
const { isSignedIn, userId } = useAuth();
const [role, setRole] = useState<string | null | undefined>(undefined);
if (isSignedIn) return <Redirect href="/(root)/(tabs)/home" />;
useEffect(() => {
if (!isSignedIn || !userId) return;
return <Redirect href="/(auth)/welcome" />;
fetchAPI(`/(api)/user?clerkId=${userId}`)
.then((res) => setRole(res?.data?.role ?? null))
.catch(() => setRole(null));
}, [isSignedIn, userId]);
if (!isSignedIn) return <Redirect href="/(auth)/welcome" />;
// Still loading the user's role from the database.
if (role === undefined) {
return (
<View className="flex-1 items-center justify-center bg-white">
<ActivityIndicator size="large" color="#0286FF" />
</View>
);
}
if (role === "driver") return <Redirect href="/(root)/driver-home" />;
if (role === "rider") return <Redirect href="/(root)/(tabs)/home" />;
// Signed in but no role chosen yet.
return <Redirect href="/(root)/role" />;
};
export default App;