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 { useState } from 'react';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { formatarWhatsapp } from '@/utils/whatsappFormatter';
|
import { formatarWhatsapp } from '@/utils/whatsappFormatter';
|
||||||
import { validateRegisterForm } from '@/utils/registerValidation';
|
import { validateRegisterForm } from '@/utils/registerValidation';
|
||||||
@ -14,6 +15,7 @@ interface RegisterFormProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const RegisterForm = ({ isLoading, setIsLoading }: RegisterFormProps) => {
|
const RegisterForm = ({ isLoading, setIsLoading }: RegisterFormProps) => {
|
||||||
|
const navigate = useNavigate();
|
||||||
const [nome, setNome] = useState('');
|
const [nome, setNome] = useState('');
|
||||||
const [empresa, setEmpresa] = useState('');
|
const [empresa, setEmpresa] = useState('');
|
||||||
const [email, setEmail] = useState('');
|
const [email, setEmail] = useState('');
|
||||||
@ -72,38 +74,33 @@ const RegisterForm = ({ isLoading, setIsLoading }: RegisterFormProps) => {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log('✅ Novo usuário cadastrado com sucesso');
|
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('📡 Enviando webhook para gerenciador n8n...');
|
||||||
console.log('📋 Email do usuário:', email);
|
console.log('📋 Email do usuário:', email);
|
||||||
console.log('📋 ID do usuário:', data.user.id);
|
console.log('📋 ID do usuário:', data.user.id);
|
||||||
|
console.log('📋 WhatsApp do usuário:', whatsapp);
|
||||||
|
|
||||||
try {
|
// Send webhook in background (don't wait for it)
|
||||||
const webhookSuccess = await sendNewUserWebhook(email, data.user.id);
|
sendNewUserWebhook(email, data.user.id, whatsapp.replace(/\D/g, ''))
|
||||||
if (webhookSuccess) {
|
.then((success) => {
|
||||||
console.log('✅ Webhook enviado com sucesso para n8n');
|
if (success) {
|
||||||
toast.success("Configuração automática iniciada!", {
|
console.log('✅ Webhook enviado com sucesso para n8n');
|
||||||
description: "Sua conta foi criada e a configuração automática do sistema foi iniciada.",
|
} else {
|
||||||
duration: 8000,
|
console.error('❌ Falha no envio do webhook para n8n');
|
||||||
});
|
}
|
||||||
} else {
|
})
|
||||||
console.error('❌ Falha no envio do webhook para n8n');
|
.catch((error) => {
|
||||||
toast.error("Aviso: Configuração", {
|
console.error('❌ Erro crítico no webhook para n8n:', error);
|
||||||
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,
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
// 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) {
|
} catch (error) {
|
||||||
|
|||||||
@ -512,6 +512,7 @@ export type Database = {
|
|||||||
status_instancia: string | null
|
status_instancia: string | null
|
||||||
webhook: string | null
|
webhook: string | null
|
||||||
whatsapp: string
|
whatsapp: string
|
||||||
|
workflow_id: string | null
|
||||||
}
|
}
|
||||||
Insert: {
|
Insert: {
|
||||||
created_at?: string
|
created_at?: string
|
||||||
@ -525,6 +526,7 @@ export type Database = {
|
|||||||
status_instancia?: string | null
|
status_instancia?: string | null
|
||||||
webhook?: string | null
|
webhook?: string | null
|
||||||
whatsapp: string
|
whatsapp: string
|
||||||
|
workflow_id?: string | null
|
||||||
}
|
}
|
||||||
Update: {
|
Update: {
|
||||||
created_at?: string
|
created_at?: string
|
||||||
@ -538,6 +540,7 @@ export type Database = {
|
|||||||
status_instancia?: string | null
|
status_instancia?: string | null
|
||||||
webhook?: string | null
|
webhook?: string | null
|
||||||
whatsapp?: string
|
whatsapp?: string
|
||||||
|
workflow_id?: string | null
|
||||||
}
|
}
|
||||||
Relationships: []
|
Relationships: []
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,30 @@
|
|||||||
|
|
||||||
import { useState } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link, useLocation } from 'react-router-dom';
|
||||||
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";
|
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||||
import LoginForm from '@/components/auth/LoginForm';
|
import LoginForm from '@/components/auth/LoginForm';
|
||||||
import RegisterForm from '@/components/auth/RegisterForm';
|
import RegisterForm from '@/components/auth/RegisterForm';
|
||||||
|
import { toast } from "sonner";
|
||||||
|
|
||||||
const Auth = () => {
|
const Auth = () => {
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
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 (
|
return (
|
||||||
<div className="flex items-center justify-center min-h-screen bg-gray-50 px-4">
|
<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>
|
<CardDescription>Gerencie suas finanças de forma simples e eficiente</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<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">
|
<TabsList className="grid w-full grid-cols-2 mb-4">
|
||||||
<TabsTrigger value="login">Login</TabsTrigger>
|
<TabsTrigger value="login">Login</TabsTrigger>
|
||||||
<TabsTrigger value="cadastro">Cadastro</TabsTrigger>
|
<TabsTrigger value="cadastro">Cadastro</TabsTrigger>
|
||||||
|
|||||||
@ -5,24 +5,28 @@ import { supabase } from "@/integrations/supabase/client";
|
|||||||
interface NewUserWebhookData {
|
interface NewUserWebhookData {
|
||||||
email: string;
|
email: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
|
whatsapp: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a webhook to the n8n workflow manager when a new user registers
|
* Sends a webhook to the n8n workflow manager when a new user registers
|
||||||
* @param email User's email
|
* @param email User's email
|
||||||
* @param userId User's ID from Supabase Auth
|
* @param userId User's ID from Supabase Auth
|
||||||
|
* @param whatsapp User's WhatsApp number
|
||||||
* @returns Success status
|
* @returns Success status
|
||||||
*/
|
*/
|
||||||
export async function sendNewUserWebhook(
|
export async function sendNewUserWebhook(
|
||||||
email: string,
|
email: string,
|
||||||
userId: string
|
userId: string,
|
||||||
|
whatsapp: string
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
try {
|
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 = {
|
const webhookData: NewUserWebhookData = {
|
||||||
email: email,
|
email: email,
|
||||||
userId: userId
|
userId: userId,
|
||||||
|
whatsapp: whatsapp
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('📋 Dados do webhook:', JSON.stringify(webhookData, null, 2));
|
console.log('📋 Dados do webhook:', JSON.stringify(webhookData, null, 2));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user