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
+21 -19
View File
@@ -1,4 +1,3 @@
import { useSignIn } from "@clerk/clerk-expo";
import { Link, useRouter } from "expo-router";
import { useCallback, useState } from "react";
import { Alert, Image, ScrollView, Text, View } from "react-native";
@@ -7,42 +6,45 @@ import { CustomButton } from "@/components/custom-button";
import { InputField } from "@/components/input-field";
import { OAuth } from "@/components/oauth";
import { icons, images } from "@/constants";
import { fetchAPI } from "@/lib/fetch";
import { useSession } from "@/lib/session";
const SignIn = () => {
const router = useRouter();
const { signIn, setActive, isLoaded } = useSignIn();
const { isLoaded, setSession } = useSession();
const [form, setForm] = useState({
email: "",
password: "",
});
const onSignInPress = useCallback(async () => {
if (!isLoaded) return;
try {
const signInAttempt = await signIn.create({
identifier: form.email,
password: form.password,
const response = await fetchAPI("/(api)/auth/login", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
email: form.email,
password: form.password,
}),
});
if (signInAttempt.status === "complete") {
await setActive({ session: signInAttempt.createdSessionId });
router.replace("/");
} else {
Alert.alert("Error", "Invalid email or password.");
setForm((prevForm) => ({
...prevForm,
password: "",
}));
}
await setSession(response.data);
router.replace("/");
} catch (err: any) {
Alert.alert("Error", err?.errors[0]?.longMessage);
const status = String(err?.message ?? "");
const message = status.includes("403")
? "Please verify your email first."
: status.includes("401")
? "Invalid email or password."
: "Could not sign in. Please try again.";
Alert.alert("Error", message);
setForm((prevForm) => ({
...prevForm,
password: "",
}));
}
}, [isLoaded, signIn, form.email, form.password, setActive, router]);
}, [isLoaded, form.email, form.password, setSession, router]);
return (
<ScrollView className="flex-1 bg-white">