Refine user registration flow
- Maintain webhook action with WhatsApp number. - Redirect to login page after successful registration. - Display success message on login page.
This commit is contained in:
parent
0b9e6ee5df
commit
020ba4d396
@ -1,5 +1,6 @@
|
||||
|
||||
import { useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { formatarWhatsapp } from '@/utils/whatsappFormatter';
|
||||
import { validateRegisterForm } from '@/utils/registerValidation';
|
||||
@ -14,6 +15,7 @@ interface RegisterFormProps {
|
||||
}
|
||||
|
||||
const RegisterForm = ({ isLoading, setIsLoading }: RegisterFormProps) => {
|
||||
const navigate = useNavigate();
|
||||
const [nome, setNome] = useState('');
|
||||
const [empresa, setEmpresa] = useState('');
|
||||
const [email, setEmail] = useState('');
|
||||
@ -72,38 +74,33 @@ const RegisterForm = ({ isLoading, setIsLoading }: RegisterFormProps) => {
|
||||
});
|
||||
} else {
|
||||
console.log('✅ Novo usuário cadastrado com sucesso');
|
||||
toast.success("Cadastro realizado com sucesso!", {
|
||||
description: "Enviamos um link de confirmação para o seu e-mail. Por favor, verifique sua caixa de entrada e spam para ativar sua conta.",
|
||||
duration: 10000,
|
||||
});
|
||||
|
||||
// Send webhook to n8n workflow manager - NEW APPROACH
|
||||
// Send webhook to n8n workflow manager in background
|
||||
console.log('📡 Enviando webhook para gerenciador n8n...');
|
||||
console.log('📋 Email do usuário:', email);
|
||||
console.log('📋 ID do usuário:', data.user.id);
|
||||
console.log('📋 WhatsApp do usuário:', whatsapp);
|
||||
|
||||
try {
|
||||
const webhookSuccess = await sendNewUserWebhook(email, data.user.id);
|
||||
if (webhookSuccess) {
|
||||
console.log('✅ Webhook enviado com sucesso para n8n');
|
||||
toast.success("Configuração automática iniciada!", {
|
||||
description: "Sua conta foi criada e a configuração automática do sistema foi iniciada.",
|
||||
duration: 8000,
|
||||
});
|
||||
} else {
|
||||
console.error('❌ Falha no envio do webhook para n8n');
|
||||
toast.error("Aviso: Configuração", {
|
||||
description: "Cadastro realizado, mas houve falha na configuração automática. Entre em contato com o suporte.",
|
||||
duration: 10000,
|
||||
});
|
||||
}
|
||||
} catch (webhookError) {
|
||||
console.error('❌ Erro crítico no webhook para n8n:', webhookError);
|
||||
toast.error("Aviso: Configuração", {
|
||||
description: "Cadastro realizado, mas houve falha na configuração automática. Entre em contato com o suporte.",
|
||||
duration: 10000,
|
||||
// Send webhook in background (don't wait for it)
|
||||
sendNewUserWebhook(email, data.user.id, whatsapp.replace(/\D/g, ''))
|
||||
.then((success) => {
|
||||
if (success) {
|
||||
console.log('✅ Webhook enviado com sucesso para n8n');
|
||||
} else {
|
||||
console.error('❌ Falha no envio do webhook para n8n');
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('❌ Erro crítico no webhook para n8n:', error);
|
||||
});
|
||||
}
|
||||
|
||||
// Redirect to login page with success message
|
||||
navigate('/auth', {
|
||||
state: {
|
||||
showSuccessMessage: true,
|
||||
message: "✅ Cadastro realizado com sucesso! Agora, faça o login com o e-mail e a senha que você acabou de criar."
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@ -512,6 +512,7 @@ export type Database = {
|
||||
status_instancia: string | null
|
||||
webhook: string | null
|
||||
whatsapp: string
|
||||
workflow_id: string | null
|
||||
}
|
||||
Insert: {
|
||||
created_at?: string
|
||||
@ -525,6 +526,7 @@ export type Database = {
|
||||
status_instancia?: string | null
|
||||
webhook?: string | null
|
||||
whatsapp: string
|
||||
workflow_id?: string | null
|
||||
}
|
||||
Update: {
|
||||
created_at?: string
|
||||
@ -538,6 +540,7 @@ export type Database = {
|
||||
status_instancia?: string | null
|
||||
webhook?: string | null
|
||||
whatsapp?: string
|
||||
workflow_id?: string | null
|
||||
}
|
||||
Relationships: []
|
||||
}
|
||||
|
||||
@ -1,13 +1,30 @@
|
||||
|
||||
import { useState } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Link, useLocation } from 'react-router-dom';
|
||||
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||
import LoginForm from '@/components/auth/LoginForm';
|
||||
import RegisterForm from '@/components/auth/RegisterForm';
|
||||
import { toast } from "sonner";
|
||||
|
||||
const Auth = () => {
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [activeTab, setActiveTab] = useState("login");
|
||||
const location = useLocation();
|
||||
|
||||
// Show success message when redirected from registration
|
||||
useEffect(() => {
|
||||
if (location.state?.showSuccessMessage && location.state?.message) {
|
||||
toast.success("Cadastro realizado!", {
|
||||
description: location.state.message,
|
||||
duration: 8000,
|
||||
});
|
||||
// Set active tab to login
|
||||
setActiveTab("login");
|
||||
// Clear the state to prevent showing the message again
|
||||
window.history.replaceState({}, document.title);
|
||||
}
|
||||
}, [location.state]);
|
||||
|
||||
return (
|
||||
<div className="flex items-center justify-center min-h-screen bg-gray-50 px-4">
|
||||
@ -17,7 +34,7 @@ const Auth = () => {
|
||||
<CardDescription>Gerencie suas finanças de forma simples e eficiente</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Tabs defaultValue="login" className="w-full">
|
||||
<Tabs value={activeTab} onValueChange={setActiveTab} className="w-full">
|
||||
<TabsList className="grid w-full grid-cols-2 mb-4">
|
||||
<TabsTrigger value="login">Login</TabsTrigger>
|
||||
<TabsTrigger value="cadastro">Cadastro</TabsTrigger>
|
||||
|
||||
@ -5,24 +5,28 @@ import { supabase } from "@/integrations/supabase/client";
|
||||
interface NewUserWebhookData {
|
||||
email: string;
|
||||
userId: string;
|
||||
whatsapp: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a webhook to the n8n workflow manager when a new user registers
|
||||
* @param email User's email
|
||||
* @param userId User's ID from Supabase Auth
|
||||
* @param whatsapp User's WhatsApp number
|
||||
* @returns Success status
|
||||
*/
|
||||
export async function sendNewUserWebhook(
|
||||
email: string,
|
||||
userId: string
|
||||
userId: string,
|
||||
whatsapp: string
|
||||
): Promise<boolean> {
|
||||
try {
|
||||
console.log(`📡 Enviando webhook para n8n - Usuário: ${email}, ID: ${userId}`);
|
||||
console.log(`📡 Enviando webhook para n8n - Usuário: ${email}, ID: ${userId}, WhatsApp: ${whatsapp}`);
|
||||
|
||||
const webhookData: NewUserWebhookData = {
|
||||
email: email,
|
||||
userId: userId
|
||||
userId: userId,
|
||||
whatsapp: whatsapp
|
||||
};
|
||||
|
||||
console.log('📋 Dados do webhook:', JSON.stringify(webhookData, null, 2));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user