import { useState } from 'react'; import { Button } from "@/components/ui/button"; import { toast } from "sonner"; import { supabase } from '@/integrations/supabase/client'; const SocialLoginButtons = () => { const [loadingGoogle, setLoadingGoogle] = useState(false); const handleGoogleLogin = async () => { setLoadingGoogle(true); try { console.log('🔐 Iniciando login com Google...'); console.log('🌐 URL atual:', window.location.origin); // Determinar a URL de redirecionamento correta baseada no hostname let redirectUrl; const hostname = window.location.hostname; if (hostname === 'localhost') { redirectUrl = 'http://localhost:3000/'; } else if (hostname.includes('financehome.innova1001.com.br')) { redirectUrl = 'https://financehome.innova1001.com.br/'; } else if (hostname.includes('lovableproject.com')) { redirectUrl = `${window.location.origin}/`; } else { // Fallback para qualquer outro domínio redirectUrl = `${window.location.origin}/`; } console.log('🔗 URL de redirecionamento:', redirectUrl); const { data, error } = await supabase.auth.signInWithOAuth({ provider: 'google', options: { redirectTo: redirectUrl, queryParams: { access_type: 'offline', prompt: 'consent', } } }); console.log('📊 Resposta do Supabase:', { data, error }); if (error) { console.error('❌ Erro no login com Google:', error); toast.error("Erro no login com Google", { description: error.message || "Não foi possível conectar com o Google. Verifique as configurações.", }); } else { console.log('✅ Redirecionamento iniciado...'); } } catch (error) { console.error('❌ Erro geral no login com Google:', error); toast.error("Erro no login", { description: "Ocorreu um erro inesperado. Verifique as configurações do Google.", }); } finally { setLoadingGoogle(false); } }; return (
Ou continue com
); }; export default SocialLoginButtons;