"use client"; import { useState } from "react"; import { toast } from "sonner"; import { Loader2 } from "lucide-react"; import { Button } from "@/components/ui/button"; import { lovable } from "@/integrations/lovable/index"; import { translateAuthError } from "@/lib/auth-errors"; export function GoogleButton({ redirectTo }: { redirectTo?: string }) { const [loading, setLoading] = useState(false); const onClick = async () => { setLoading(true); try { const url = redirectTo ? `${window.location.origin}${redirectTo}` : window.location.origin; const result = await lovable.auth.signInWithOAuth("google", { redirect_uri: url }); if (result.error) { toast.error(translateAuthError(result.error.message)); setLoading(false); return; } if (result.redirected) return; // tokens recebidos: redireciona window.location.href = url; } catch (e) { toast.error(translateAuthError(e instanceof Error ? e.message : String(e))); setLoading(false); } }; return ( ); }