Add self-hosted auth, admin API, and owner web dashboard
- Replace Clerk with self-hosted JWT auth (register/login/verify, bcrypt passwords, Gmail OTP with console fallback) - Add lib/db.ts pg pool + transaction helpers; seed script migrates legacy Clerk-era schema (drop clerk_id, enforce UUID ids and unique email) - Add owner-gated admin API: stats, users, drivers CRUD, rides - Add dashboard/ Vite React owner dashboard (login, overview, users, fleet, rides) with dev-server proxy to avoid Expo CORS middleware - Add scripts/set-owner.mjs for role management
This commit is contained in:
+19
-5
@@ -1,21 +1,35 @@
|
||||
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";
|
||||
import { useSession } from "@/lib/session";
|
||||
|
||||
const App = () => {
|
||||
const { isSignedIn, userId } = useAuth();
|
||||
const { isLoaded, isSignedIn, user } = useSession();
|
||||
const [role, setRole] = useState<string | null | undefined>(undefined);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isSignedIn || !userId) return;
|
||||
if (!isSignedIn) return;
|
||||
|
||||
fetchAPI(`/(api)/user?clerkId=${userId}`)
|
||||
// Prefer the role cached at sign-in; fall back to a fresh fetch.
|
||||
if (user?.role !== undefined && user?.role !== null) {
|
||||
setRole(user.role);
|
||||
return;
|
||||
}
|
||||
|
||||
fetchAPI("/(api)/user")
|
||||
.then((res) => setRole(res?.data?.role ?? null))
|
||||
.catch(() => setRole(null));
|
||||
}, [isSignedIn, userId]);
|
||||
}, [isSignedIn, user]);
|
||||
|
||||
if (!isLoaded) {
|
||||
return (
|
||||
<View className="flex-1 items-center justify-center bg-white">
|
||||
<ActivityIndicator size="large" color="#0286FF" />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
if (!isSignedIn) return <Redirect href="/(auth)/welcome" />;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user