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
+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>
);