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
+1 -1
View File
@@ -30,7 +30,7 @@ export const DriverCard = ({
<View className="flex flex-row items-center space-x-1 ml-2">
<Image source={icons.star} alt="Star" className="w-3.5 h-3.5" />
<Text className="text-sm font-JakartaRegular">4</Text>
<Text className="text-sm font-JakartaRegular">{item.rating}</Text>
</View>
</View>
+6 -2
View File
@@ -19,7 +19,7 @@ interface Suggestion {
}
// Places API (New) — the legacy Places web service is unavailable to
// newer Google Cloud projects.
// newer Google Cloud projects. Results are restricted to Lebanon.
const fetchSuggestions = async (input: string): Promise<Suggestion[]> => {
const res = await fetch(
"https://places.googleapis.com/v1/places:autocomplete",
@@ -29,7 +29,11 @@ const fetchSuggestions = async (input: string): Promise<Suggestion[]> => {
"Content-Type": "application/json",
"X-Goog-Api-Key": googleApiKey,
},
body: JSON.stringify({ input, languageCode: "en" }),
body: JSON.stringify({
input,
languageCode: "en",
includedRegionCodes: ["lb"],
}),
},
);
const data = await res.json();
+2 -2
View File
@@ -45,10 +45,10 @@ export const Map = () => {
setMarkers(newMarkers);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [drivers]);
}, [drivers, userLatitude, userLongitude]);
useEffect(() => {
if (markers.length > 0 && destinationLatitude && destinationLatitude) {
if (markers.length > 0 && destinationLatitude && destinationLongitude) {
calculateDriverTimes({
markers,
userLatitude,
+37 -17
View File
@@ -1,10 +1,11 @@
import { useOAuth } from "@clerk/clerk-expo";
import * as Google from "expo-auth-session/providers/google";
import { router } from "expo-router";
import { useCallback } from "react";
import { useCallback, useEffect } from "react";
import { Image, Text, View, Alert } from "react-native";
import { icons } from "@/constants";
import { googleOAuth } from "@/lib/auth";
import { googleAuth } from "@/lib/auth";
import { useSession } from "@/lib/session";
import { CustomButton } from "./custom-button";
@@ -13,23 +14,41 @@ type OAuthProps = {
};
export const OAuth = ({ title }: OAuthProps) => {
const { startOAuthFlow } = useOAuth({ strategy: "oauth_google" });
const { setSession } = useSession();
const handleGoogleOAuth = useCallback(async () => {
try {
const result = await googleOAuth(startOAuthFlow);
const [request, response, promptAsync] = Google.useIdTokenAuthRequest({
clientId: process.env.EXPO_PUBLIC_GOOGLE_AUTH_WEB_CLIENT_ID,
iosClientId: process.env.EXPO_PUBLIC_GOOGLE_AUTH_IOS_CLIENT_ID,
androidClientId: process.env.EXPO_PUBLIC_GOOGLE_AUTH_ANDROID_CLIENT_ID,
});
if (result?.code === "session_exists" || result?.code === "success") {
router.replace("/");
}
} catch (err: any) {
console.error("OAuth error", err);
Alert.alert(
"Google sign-in failed",
err?.errors?.[0]?.longMessage || err?.message || "Please try again.",
);
useEffect(() => {
if (response?.type !== "success") return;
const idToken = response.params?.id_token;
if (!idToken) {
Alert.alert("Google sign-in failed", "No token returned. Try again.");
return;
}
}, [startOAuthFlow]);
void (async () => {
try {
await setSession(await googleAuth(idToken));
router.replace("/");
} catch (err: any) {
console.error("OAuth error", err);
Alert.alert(
"Google sign-in failed",
err?.message || "Please try again.",
);
}
})();
}, [response, setSession]);
const handleGoogleOAuth = useCallback(() => {
void promptAsync();
}, [promptAsync]);
return (
<View>
@@ -55,6 +74,7 @@ export const OAuth = ({ title }: OAuthProps) => {
bgVariant="outline"
textVariant="primary"
onPress={handleGoogleOAuth}
disabled={!request}
/>
</View>
);
+87 -13
View File
@@ -1,17 +1,19 @@
import { useAuth } from "@clerk/clerk-expo";
import { router } from "expo-router";
import * as WebBrowser from "expo-web-browser";
import { useState } from "react";
import { Alert, Image, Text, View } from "react-native";
import { Alert, Image, Text, TouchableOpacity, View } from "react-native";
import ReactNativeModal from "react-native-modal";
import { images } from "@/constants";
import { fetchAPI } from "@/lib/fetch";
import { formatLBP } from "@/lib/pricing";
import { useLocationStore } from "@/store";
import type { PaymentProps } from "@/types/type";
import { CustomButton } from "./custom-button";
type PaymentMethod = "cash" | "card";
export const Payment = ({
fullName,
email,
@@ -27,11 +29,11 @@ export const Payment = ({
destinationAddress,
destinationLongitude,
} = useLocationStore();
const { userId } = useAuth();
const [method, setMethod] = useState<PaymentMethod>("cash");
const [success, setSuccess] = useState(false);
const [processing, setProcessing] = useState(false);
const recordRide = async () => {
const recordRide = async (paymentStatus: string) => {
await fetchAPI("/(api)/ride/create", {
method: "POST",
headers: {
@@ -45,15 +47,31 @@ export const Payment = ({
destination_latitude: destinationLatitude,
destination_longitude: destinationLongitude,
ride_time: rideTime.toFixed(0),
fare_price: parseInt(amount) * 100, // in cents
payment_status: "paid",
fare_price: Math.round(parseFloat(amount) * 100), // in cents
payment_status: paymentStatus,
driver_id: driverId,
user_id: userId,
}),
});
};
const payWithAreeba = async () => {
// Cash is settled directly with the driver at drop-off.
const payWithCash = async () => {
setProcessing(true);
try {
await recordRide("cash");
setSuccess(true);
} catch (err) {
console.log("[PAYMENT]: ", err);
Alert.alert(
"Error",
"Something went wrong while booking your ride. Please try again.",
);
} finally {
setProcessing(false);
}
};
const payWithCard = async () => {
setProcessing(true);
try {
@@ -99,7 +117,7 @@ export const Payment = ({
});
if (verification.success) {
await recordRide();
await recordRide("paid");
setSuccess(true);
} else {
Alert.alert(
@@ -118,12 +136,66 @@ export const Payment = ({
}
};
const confirm = () =>
method === "cash"
? payWithCash()
: Alert.alert("Pay by card", `Your card will be charged $${amount}.`, [
{ text: "Cancel", style: "cancel" },
{ text: "Continue", onPress: () => void payWithCard() },
]);
return (
<>
<Text className="text-lg font-JakartaSemiBold mt-4 mb-2">
Payment Method
</Text>
<View className="flex flex-row gap-x-3">
<TouchableOpacity
onPress={() => setMethod("cash")}
className={`flex-1 items-center py-3 rounded-xl border ${
method === "cash"
? "bg-general-600 border-primary-500"
: "bg-white border-general-700"
}`}
>
<Text
className={`font-JakartaMedium ${
method === "cash" ? "text-white" : "text-black"
}`}
>
💵 Cash
</Text>
</TouchableOpacity>
<TouchableOpacity
onPress={() => setMethod("card")}
className={`flex-1 items-center py-3 rounded-xl border ${
method === "card"
? "bg-general-600 border-primary-500"
: "bg-white border-general-700"
}`}
>
<Text
className={`font-JakartaMedium ${
method === "card" ? "text-white" : "text-black"
}`}
>
💳 Card
</Text>
</TouchableOpacity>
</View>
<CustomButton
title={processing ? "Processing..." : "Confirm ride"}
className="my-2"
onPress={payWithAreeba}
title={
processing
? "Processing..."
: method === "cash"
? "Book ride · Pay cash to driver"
: "Confirm & Pay by Card"
}
className="my-2 mt-4"
onPress={confirm}
disabled={processing}
/>
@@ -141,7 +213,9 @@ export const Payment = ({
<Text className="text-base text-general-200 text-JakartaMedium text-center mt-3">
Thank you for your booking.{"\n"} Your reservation has been placed.
{"\n"}
Please proceed with your trip.
{method === "cash"
? `Please have ${formatLBP(parseFloat(amount))} ready.`
: null}
</Text>
<CustomButton
+16 -2
View File
@@ -82,15 +82,29 @@ export const RideCard = ({ ride }: { ride: Ride }) => {
</Text>
</View>
<View className="flex flex-row items-center w-full justify-between mb-5">
<Text className="font-JakartaMedium text-gray-500 text-xs">
Fare
</Text>
<Text className="font-JakartaMedium text-gray-500 text-xs">
${(ride.fare_price / 100).toFixed(2)}
</Text>
</View>
<View className="flex flex-row items-center w-full justify-between mb-5">
<Text className="font-JakartaMedium text-gray-500 text-xs">
Payment Status
</Text>
<Text
className={`font-JakartaMedium capitalize text-gray-500 text-xs ${payment_status === "paid" ? "text-emerald-500" : "text-rose-500"}`}
className={`font-JakartaMedium capitalize text-xs ${payment_status === "paid" ? "text-emerald-500" : "text-gray-500"}`}
>
{payment_status}
{payment_status === "cash"
? "Cash · Pay to driver"
: payment_status === "paid"
? "Paid by card"
: payment_status}
</Text>
</View>
</View>