import { useOAuth } from "@clerk/clerk-expo"; import { router } from "expo-router"; import { useCallback } from "react"; import { Image, Text, View, Alert } from "react-native"; import { icons } from "@/constants"; import { googleOAuth } from "@/lib/auth"; import { CustomButton } from "./custom-button"; type OAuthProps = { title: string; }; export const OAuth = ({ title }: OAuthProps) => { const { startOAuthFlow } = useOAuth({ strategy: "oauth_google" }); const handleGoogleOAuth = useCallback(async () => { try { const result = await googleOAuth(startOAuthFlow); 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.", ); } }, [startOAuthFlow]); return ( Or ( Google logo )} bgVariant="outline" textVariant="primary" onPress={handleGoogleOAuth} /> ); };