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
+4 -19
View File
@@ -1,6 +1,5 @@
import { useAuth, useUser } from "@clerk/clerk-expo";
import * as Location from "expo-location";
import { Link, router } from "expo-router";
import { router } from "expo-router";
import { useEffect, useState } from "react";
import {
ActivityIndicator,
@@ -15,16 +14,15 @@ import { SafeAreaView } from "react-native-safe-area-context";
import { GoogleTextInput } from "@/components/google-text-input";
import { Map } from "@/components/map";
import { RideCard } from "@/components/ride-card";
import { LINKS } from "@/config";
import { icons, images } from "@/constants";
import { useSession } from "@/lib/session";
import { useLocationStore } from "@/store";
import { useFetch } from "@/lib/fetch";
import type { Ride } from "@/types/type";
const Home = () => {
const { setUserLocation, setDestinationLocation } = useLocationStore();
const { signOut } = useAuth();
const { user } = useUser();
const { signOut, user } = useSession();
const { data: recentRides, loading } = useFetch<Ride[]>(
`/(api)/ride/${user?.id}`,
);
@@ -119,23 +117,10 @@ const Home = () => {
numberOfLines={1}
>
Welcome{" "}
{user?.firstName || user?.emailAddresses[0].emailAddress} 👋
{user?.name || user?.email} 👋
</Text>
<View className="flex flex-row items-center gap-x-1">
<Link
href={LINKS.sourceCode}
target="_blank"
rel="noreferrer noopener"
className="justify-center items-center w-10 h-10"
>
<Image
source={icons.github}
className="w-6 h-6"
alt="GitHub"
/>
</Link>
<TouchableOpacity
onPress={handleSignOut}
className="justify-center items-center w-10 h-10 rounded-full bg-white"
+6 -10
View File
@@ -1,11 +1,11 @@
import { useUser } from "@clerk/clerk-expo";
import { Image, ScrollView, Text, View } from "react-native";
import { SafeAreaView } from "react-native-safe-area-context";
import { InputField } from "@/components/input-field";
import { useSession } from "@/lib/session";
const Profile = () => {
const { user } = useUser();
const { user } = useSession();
return (
<SafeAreaView className="flex-1">
@@ -17,9 +17,7 @@ const Profile = () => {
<View className="flex items-center justify-center my-5">
<Image
source={{
uri: user?.externalAccounts[0]?.imageUrl ?? user?.imageUrl,
}}
source={{ uri: user?.avatarUrl ?? undefined }}
alt="Your Avatar"
style={{ width: 110, height: 110, borderRadius: 110 / 2 }}
className=" rounded-full h-[110px] w-[110px] border-[3px] border-white shadow-sm shadow-neutral-300"
@@ -30,7 +28,7 @@ const Profile = () => {
<View className="flex flex-col items-start justify-start w-full">
<InputField
label="First name"
placeholder={user?.firstName ?? "Your First name"}
placeholder={user?.name.split(" ")[0] ?? "Your First name"}
containerStyles="w-full mb-4"
inputStyles="p-3.5"
editable={false}
@@ -38,7 +36,7 @@ const Profile = () => {
<InputField
label="Last name"
placeholder={user?.lastName ?? "Your Last name"}
placeholder={user?.name.split(" ").slice(1).join(" ") ?? "Your Last name"}
containerStyles="w-full mb-4"
inputStyles="p-3.5"
editable={false}
@@ -46,9 +44,7 @@ const Profile = () => {
<InputField
label="Email"
placeholder={
user?.primaryEmailAddress?.emailAddress ?? "Your Email address"
}
placeholder={user?.email ?? "Your Email address"}
containerStyles="w-full mb-4"
inputStyles="p-3.5"
editable={false}
+2 -2
View File
@@ -1,14 +1,14 @@
import { useUser } from "@clerk/clerk-expo";
import { ActivityIndicator, FlatList, Image, Text, View } from "react-native";
import { SafeAreaView } from "react-native-safe-area-context";
import { RideCard } from "@/components/ride-card";
import { images } from "@/constants";
import { useFetch } from "@/lib/fetch";
import { useSession } from "@/lib/session";
import type { Ride } from "@/types/type";
const Rides = () => {
const { user } = useUser();
const { user } = useSession();
const { data: recentRides, loading } = useFetch<Ride[]>(
`/(api)/ride/${user?.id}`,
);
+34 -7
View File
@@ -1,14 +1,17 @@
import { useUser } from "@clerk/clerk-expo";
import { router } from "expo-router";
import { Image, Text, View } from "react-native";
import { CustomButton } from "@/components/custom-button";
import { Payment } from "@/components/payment";
import { RideLayout } from "@/components/ride-layout";
import { icons } from "@/constants";
import { formatLBP } from "@/lib/pricing";
import { useSession } from "@/lib/session";
import { formatTime } from "@/lib/utils";
import { useDriverStore, useLocationStore } from "@/store";
const BookRide = () => {
const { user } = useUser();
const { user } = useSession();
const { userAddress, destinationAddress } = useLocationStore();
const { drivers, selectedDriver } = useDriverStore();
@@ -16,6 +19,24 @@ const BookRide = () => {
(driver) => +driver.id === selectedDriver,
)[0];
if (!driverDetails) {
return (
<RideLayout title="Book Ride">
<View className="flex-1 items-center justify-center">
<Text className="text-base text-general-200 font-JakartaMedium text-center">
No driver selected.{"\n"}Please go back and choose a driver first.
</Text>
<CustomButton
title="Choose a Driver"
onPress={() => router.replace("/(root)/confirm-ride")}
className="mt-6"
/>
</View>
</RideLayout>
);
}
return (
<RideLayout title="Book Ride">
<>
@@ -54,9 +75,15 @@ const BookRide = () => {
<View className="flex flex-row items-center justify-between w-full border-b border-white py-3">
<Text className="text-lg font-JakartaRegular">Ride Price</Text>
<Text className="text-lg font-JakartaRegular text-[#0CC25F]">
${driverDetails?.price}
</Text>
<View className="flex flex-col items-end">
<Text className="text-lg font-JakartaRegular text-[#0CC25F]">
${driverDetails?.price}
</Text>
<Text className="text-xs font-JakartaRegular text-general-200">
{formatLBP(parseFloat(driverDetails?.price ?? "0"))}
</Text>
</View>
</View>
<View className="flex flex-row items-center justify-between w-full border-b border-white py-3">
@@ -95,8 +122,8 @@ const BookRide = () => {
</View>
<Payment
fullName={user?.fullName ?? ""}
email={user?.emailAddresses[0].emailAddress ?? ""}
fullName={user?.name ?? ""}
email={user?.email ?? ""}
amount={driverDetails?.price ?? "0"}
driverId={driverDetails?.id}
rideTime={driverDetails?.time ?? 0}
+9 -1
View File
@@ -1,5 +1,5 @@
import { router } from "expo-router";
import { FlatList, View } from "react-native";
import { FlatList, Text, View } from "react-native";
import { CustomButton } from "@/components/custom-button";
import { DriverCard } from "@/components/driver-card";
@@ -20,11 +20,19 @@ const ConfirmRide = () => {
setSelected={() => setSelectedDriver(item.id)}
/>
)}
ListEmptyComponent={() => (
<Text className="text-center text-general-200 font-JakartaMedium mt-10">
No drivers available on this route right now.{"\n"}Please try
another destination.
</Text>
)}
ListFooterComponent={() => (
<View className="mx-5 mt-10">
<CustomButton
title="Select Ride"
onPress={() => router.push("/(root)/book-ride")}
disabled={selectedDriver === null}
className={selectedDriver === null ? "opacity-50" : ""}
/>
</View>
)}
+4 -5
View File
@@ -1,16 +1,15 @@
import { useClerk, useUser } from "@clerk/clerk-expo";
import { Image, Text, View } from "react-native";
import { SafeAreaView } from "react-native-safe-area-context";
import { CustomButton } from "@/components/custom-button";
import { images } from "@/constants";
import { useSession } from "@/lib/session";
// Placeholder driver home. The driver experience (going online, accepting
// rides) is not built yet — drivers are registered here and managed in the
// database for now.
const DriverHome = () => {
const { user } = useUser();
const { signOut } = useClerk();
const { signOut, user } = useSession();
return (
<SafeAreaView className="flex-1 bg-white justify-center items-center px-7">
@@ -21,12 +20,12 @@ const DriverHome = () => {
/>
<Text className="text-2xl font-JakartaBold text-center">
You&apos;re registered as a driver, {user?.firstName || "there"}!
You&apos;re registered as a driver, {user?.name || "there"}!
</Text>
<Text className="text-base text-general-200 font-Jakarta text-center mt-3">
Driver mode is coming soon. We&apos;ll contact you at{" "}
{user?.emailAddresses[0]?.emailAddress} once your account is activated.
{user?.email} once your account is activated.
</Text>
<CustomButton
+12 -1
View File
@@ -10,10 +10,20 @@ const FindRide = () => {
const {
userAddress,
destinationAddress,
userLatitude,
userLongitude,
destinationLatitude,
destinationLongitude,
setDestinationLocation,
setUserLocation,
} = useLocationStore();
const canFind =
!!userLatitude &&
!!userLongitude &&
!!destinationLatitude &&
!!destinationLongitude;
return (
<RideLayout title="Ride" snapPoints={["85%"]}>
<View className="my-3">
@@ -43,7 +53,8 @@ const FindRide = () => {
<CustomButton
title="Find now"
onPress={() => router.push("/(root)/confirm-ride")}
className="mt-5"
disabled={!canFind}
className={`mt-5 ${!canFind ? "opacity-50" : ""}`}
/>
</RideLayout>
);
+6 -4
View File
@@ -1,17 +1,17 @@
import { useUser } from "@clerk/clerk-expo";
import { router } from "expo-router";
import { useState } from "react";
import { Alert, Text, TouchableOpacity, View } from "react-native";
import { SafeAreaView } from "react-native-safe-area-context";
import { fetchAPI } from "@/lib/fetch";
import { useSession } from "@/lib/session";
const RoleSelection = () => {
const { user } = useUser();
const { setUserRole } = useSession();
const [saving, setSaving] = useState(false);
const chooseRole = async (role: "rider" | "driver") => {
if (!user?.id || saving) return;
if (saving) return;
setSaving(true);
@@ -19,11 +19,13 @@ const RoleSelection = () => {
const { error } = await fetchAPI("/(api)/user", {
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ clerkId: user.id, role }),
body: JSON.stringify({ role }),
});
if (error) throw new Error(error);
setUserRole(role);
router.replace(
role === "driver" ? "/(root)/driver-home" : "/(root)/(tabs)/home",
);