- 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
82 lines
2.1 KiB
TypeScript
82 lines
2.1 KiB
TypeScript
import * as Google from "expo-auth-session/providers/google";
|
|
import { router } from "expo-router";
|
|
import { useCallback, useEffect } from "react";
|
|
import { Image, Text, View, Alert } from "react-native";
|
|
|
|
import { icons } from "@/constants";
|
|
import { googleAuth } from "@/lib/auth";
|
|
import { useSession } from "@/lib/session";
|
|
|
|
import { CustomButton } from "./custom-button";
|
|
|
|
type OAuthProps = {
|
|
title: string;
|
|
};
|
|
|
|
export const OAuth = ({ title }: OAuthProps) => {
|
|
const { setSession } = useSession();
|
|
|
|
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,
|
|
});
|
|
|
|
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;
|
|
}
|
|
|
|
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>
|
|
<View className="flex flex-row justify-center items-center mt-4 gap-x-3">
|
|
<View className="flex-1 h-px bg-general-100" />
|
|
|
|
<Text className="text-lg">Or</Text>
|
|
|
|
<View className="flex-1 h-px bg-general-100" />
|
|
</View>
|
|
|
|
<CustomButton
|
|
title={title}
|
|
className="mt-5 w-full shadow-none"
|
|
iconLeft={() => (
|
|
<Image
|
|
source={icons.google}
|
|
alt="Google logo"
|
|
resizeMode="contain"
|
|
className="h-5 w-5 mx-2"
|
|
/>
|
|
)}
|
|
bgVariant="outline"
|
|
textVariant="primary"
|
|
onPress={handleGoogleOAuth}
|
|
disabled={!request}
|
|
/>
|
|
</View>
|
|
);
|
|
};
|