Fix: Redirect after Google login and webhook timing
Redirect users to the dashboard after Google login. Move webhook calls for workflow and Evolution API activation to the "Cadastrar grupo" button click in CreateGroupFormSimple.tsx, removing them from instance creation.
This commit is contained in:
parent
17810e5c86
commit
09ffd66b47
@ -14,22 +14,22 @@ const SocialLoginButtons = () => {
|
|||||||
console.log('🔐 Iniciando login com Google...');
|
console.log('🔐 Iniciando login com Google...');
|
||||||
console.log('🌐 URL atual:', window.location.origin);
|
console.log('🌐 URL atual:', window.location.origin);
|
||||||
|
|
||||||
// Determinar a URL de redirecionamento correta baseada no hostname
|
// Determinar a URL de redirecionamento correta baseada no hostname - SEMPRE para /dashboard
|
||||||
let redirectUrl;
|
let redirectUrl;
|
||||||
const hostname = window.location.hostname;
|
const hostname = window.location.hostname;
|
||||||
|
|
||||||
if (hostname === 'localhost') {
|
if (hostname === 'localhost') {
|
||||||
redirectUrl = 'http://localhost:3000/';
|
redirectUrl = 'http://localhost:3000/dashboard';
|
||||||
} else if (hostname.includes('financehome.innova1001.com.br')) {
|
} else if (hostname.includes('financehome.innova1001.com.br')) {
|
||||||
redirectUrl = 'https://financehome.innova1001.com.br/';
|
redirectUrl = 'https://financehome.innova1001.com.br/dashboard';
|
||||||
} else if (hostname.includes('lovableproject.com')) {
|
} else if (hostname.includes('lovableproject.com')) {
|
||||||
redirectUrl = `${window.location.origin}/`;
|
redirectUrl = `${window.location.origin}/dashboard`;
|
||||||
} else {
|
} else {
|
||||||
// Fallback para qualquer outro domínio
|
// Fallback para qualquer outro domínio - sempre para dashboard
|
||||||
redirectUrl = `${window.location.origin}/`;
|
redirectUrl = `${window.location.origin}/dashboard`;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('🔗 URL de redirecionamento:', redirectUrl);
|
console.log('🔗 URL de redirecionamento (DASHBOARD):', redirectUrl);
|
||||||
|
|
||||||
const { data, error } = await supabase.auth.signInWithOAuth({
|
const { data, error } = await supabase.auth.signInWithOAuth({
|
||||||
provider: 'google',
|
provider: 'google',
|
||||||
|
|||||||
@ -73,34 +73,32 @@ const CreateGroupFormSimple = ({ userEmail, onSuccess }: CreateGroupFormProps) =
|
|||||||
|
|
||||||
await createWorkflowInN8n(userEmail);
|
await createWorkflowInN8n(userEmail);
|
||||||
|
|
||||||
// Ativar workflow (webhook ativarworkflow) APENAS UMA VEZ
|
// AGORA SIM: Ativar workflow (webhook ativarworkflow) APENAS NO MOMENTO DE CADASTRAR GRUPO
|
||||||
if (!workflowAtivado) {
|
console.log('🔔 [GRUPO] Enviando webhook ativarworkflow no momento do cadastro do grupo');
|
||||||
setMensagemStatus({ tipo: 'info', texto: 'Ativando workflow...' });
|
setMensagemStatus({ tipo: 'info', texto: 'Ativando workflow...' });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log(`🔔 Enviando webhook ativarworkflow para usuário: ${userEmail}`);
|
console.log(`🔔 Enviando webhook ativarworkflow para usuário: ${userEmail}`);
|
||||||
await activateUserWorkflow(userEmail);
|
await activateUserWorkflow(userEmail);
|
||||||
setWorkflowAtivado(true);
|
setWorkflowAtivado(true);
|
||||||
console.log('✅ Webhook ativarworkflow enviado com sucesso');
|
console.log('✅ [GRUPO] Webhook ativarworkflow enviado com sucesso no cadastro do grupo');
|
||||||
} catch (workflowError) {
|
} catch (workflowError) {
|
||||||
console.error('❌ Erro ao enviar webhook ativarworkflow:', workflowError);
|
console.error('❌ Erro ao enviar webhook ativarworkflow:', workflowError);
|
||||||
// Continua mesmo se o webhook falhar
|
// Continua mesmo se o webhook falhar
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enviar webhook para N8N configurar webhook da Evolution API APENAS UMA VEZ
|
// AGORA SIM: Enviar webhook para N8N configurar webhook da Evolution API APENAS NO MOMENTO DE CADASTRAR GRUPO
|
||||||
if (!webhookEnviado) {
|
console.log('🔔 [GRUPO] Enviando webhook de configuração no momento do cadastro do grupo');
|
||||||
setMensagemStatus({ tipo: 'info', texto: 'Configurando webhook...' });
|
setMensagemStatus({ tipo: 'info', texto: 'Configurando webhook...' });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log(`🔔 Enviando email para N8N configurar webhook: ${userEmail}`);
|
console.log(`🔔 Enviando email para N8N configurar webhook: ${userEmail}`);
|
||||||
await createEvolutionWebhook(userEmail);
|
await createEvolutionWebhook(userEmail);
|
||||||
setWebhookEnviado(true);
|
setWebhookEnviado(true);
|
||||||
console.log('✅ Email enviado com sucesso para N8N');
|
console.log('✅ [GRUPO] Email enviado com sucesso para N8N no cadastro do grupo');
|
||||||
} catch (webhookError) {
|
} catch (webhookError) {
|
||||||
console.error('❌ Erro ao enviar email para N8N:', webhookError);
|
console.error('❌ Erro ao enviar email para N8N:', webhookError);
|
||||||
// Continua mesmo se o webhook falhar
|
// Continua mesmo se o webhook falhar
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setMensagemStatus({
|
setMensagemStatus({
|
||||||
|
|||||||
@ -3,7 +3,6 @@ import { useState } from 'react';
|
|||||||
import { useToast } from '@/hooks/use-toast';
|
import { useToast } from '@/hooks/use-toast';
|
||||||
import { createWhatsAppInstance } from '@/services/whatsAppService';
|
import { createWhatsAppInstance } from '@/services/whatsAppService';
|
||||||
import { updateUserWhatsAppInstance } from '@/services/whatsAppInstanceService';
|
import { updateUserWhatsAppInstance } from '@/services/whatsAppInstanceService';
|
||||||
import { activateUserWorkflow } from '@/services/whatsAppInstance/workflowOperations';
|
|
||||||
import { WhatsAppInstance } from '@/types/whatsAppTypes';
|
import { WhatsAppInstance } from '@/types/whatsAppTypes';
|
||||||
|
|
||||||
export const useInstanceCreation = (
|
export const useInstanceCreation = (
|
||||||
@ -75,22 +74,10 @@ export const useInstanceCreation = (
|
|||||||
});
|
});
|
||||||
console.log('✅ [INSTÂNCIA] Instância registrada no banco de dados com status "conectado"');
|
console.log('✅ [INSTÂNCIA] Instância registrada no banco de dados com status "conectado"');
|
||||||
|
|
||||||
// 3. Ativar o workflow do usuário no n8n - CORRIGINDO AQUI
|
// REMOVIDO: Envio de webhooks foi movido para o momento de "cadastrar grupo"
|
||||||
console.log('🔄 [INSTÂNCIA] Passo 3: Ativando workflow do usuário no n8n...');
|
console.log('ℹ️ [INSTÂNCIA] Webhooks serão enviados apenas no momento de cadastrar grupos');
|
||||||
try {
|
|
||||||
console.log(`🔔 Enviando webhook ativarworkflow para usuário: ${userEmail}`);
|
|
||||||
await activateUserWorkflow(userEmail);
|
|
||||||
console.log('✅ [INSTÂNCIA] Webhook ativarworkflow enviado com sucesso');
|
|
||||||
} catch (workflowError) {
|
|
||||||
console.error('⚠️ [INSTÂNCIA] Erro ao enviar webhook ativarworkflow:', workflowError);
|
|
||||||
toast({
|
|
||||||
title: "Aviso",
|
|
||||||
description: "Instância criada, mas houve um problema ao ativar a automação. Entre em contato com o suporte.",
|
|
||||||
variant: "destructive",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. Criar objeto da instância
|
// 3. Criar objeto da instância
|
||||||
const newInstance: WhatsAppInstance = {
|
const newInstance: WhatsAppInstance = {
|
||||||
instanceName,
|
instanceName,
|
||||||
instanceId: instanceName,
|
instanceId: instanceName,
|
||||||
@ -103,23 +90,23 @@ export const useInstanceCreation = (
|
|||||||
|
|
||||||
console.log('✅ [INSTÂNCIA] Nova instância criada:', newInstance);
|
console.log('✅ [INSTÂNCIA] Nova instância criada:', newInstance);
|
||||||
|
|
||||||
// 5. Atualizar estado para evitar nova criação
|
// 4. Atualizar estado para evitar nova criação
|
||||||
setHasExistingInstance(true);
|
setHasExistingInstance(true);
|
||||||
setExistingInstanceData({
|
setExistingInstanceData({
|
||||||
instancia_zap: instanceName,
|
instancia_zap: instanceName,
|
||||||
status_instancia: 'conectado'
|
status_instancia: 'conectado'
|
||||||
});
|
});
|
||||||
|
|
||||||
// 6. Notificar componente pai
|
// 5. Notificar componente pai
|
||||||
onInstanceCreated(newInstance);
|
onInstanceCreated(newInstance);
|
||||||
|
|
||||||
// 7. Forçar um pequeno delay para garantir que o banco foi atualizado
|
// 6. Forçar um pequeno delay para garantir que o banco foi atualizado
|
||||||
console.log('⏳ [INSTÂNCIA] Aguardando propagação das mudanças no banco...');
|
console.log('⏳ [INSTÂNCIA] Aguardando propagação das mudanças no banco...');
|
||||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: "Sucesso!",
|
title: "Sucesso!",
|
||||||
description: "Instância do WhatsApp criada e ativada com sucesso! Agora você pode criar grupos.",
|
description: "Instância do WhatsApp criada com sucesso! Agora você pode criar grupos.",
|
||||||
duration: 5000
|
duration: 5000
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user