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.
This commit is contained in:
parent
1af58e1605
commit
317596e4ae
@ -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');
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user