From 317596e4aed5433764b12a1834bc956d26f5e47d Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Tue, 5 Aug 2025 16:33:43 +0000 Subject: [PATCH] Fix user profile completion flow The user is experiencing an issue where after manually signing up, verifying their email, and attempting to complete their profile, they are redirected to the landing page instead of the dashboard. The profile completion form reappears upon subsequent attempts, and the user record is not being created in the database. This commit addresses the issue by ensuring that user data is correctly created in the `usuarios` table upon profile completion, resolving the redirection and access problems. --- src/pages/CompleteProfile.tsx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/pages/CompleteProfile.tsx b/src/pages/CompleteProfile.tsx index af08432..4d7f851 100644 --- a/src/pages/CompleteProfile.tsx +++ b/src/pages/CompleteProfile.tsx @@ -70,18 +70,21 @@ const CompleteProfile = () => { console.log('📝 Salvando dados complementares do perfil...'); const whatsappOnly = whatsapp.replace(/\D/g, ''); - // Atualizar dados do usuário no Supabase - const { error: updateError } = await supabase + // Criar/atualizar dados do usuário no Supabase usando UPSERT + const { error: upsertError } = await supabase .from('usuarios') - .update({ + .upsert({ + id: userId, // Usar o ID do auth.users + email: userEmail.toLowerCase().trim(), nome: nome.trim(), empresa: empresa.trim() || null, whatsapp: whatsappOnly - }) - .eq('email', userEmail.toLowerCase().trim()); + }, { + onConflict: 'email' // Se já existir, atualizar baseado no email + }); - if (updateError) { - console.error('❌ Erro ao atualizar usuário:', updateError); + if (upsertError) { + console.error('❌ Erro ao salvar usuário:', upsertError); throw new Error('Erro ao salvar dados do perfil'); }