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:
Krikorios
2026-08-23 16:38:41 +03:00
parent fbe92c9d16
commit a0b297285a
75 changed files with 5158 additions and 2837 deletions
+19 -5
View File
@@ -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" />;