fix: refactor auth register to use pinia, clean up MapView obsolete telemetry call
This commit is contained in:
@ -1,10 +1,9 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { authService } from '@/services/authService'
|
||||
import { analyticsService } from '@/services/analyticsService'
|
||||
import { supabase } from '@/supabase'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import { analyticsService } from '@/services/analyticsService'
|
||||
|
||||
const emit = defineEmits(['toggle', 'success'])
|
||||
|
||||
@ -22,42 +21,36 @@ const showPassword = ref(false)
|
||||
const handleRegister = async () => {
|
||||
isLoading.value = true
|
||||
errorMessage.value = ''
|
||||
console.log('Intentando registrar usuario...')
|
||||
|
||||
try {
|
||||
const cleanEmail = email.value.trim().toLowerCase()
|
||||
const cleanPass = password.value
|
||||
|
||||
const regResponse = await authService.registerPassenger({
|
||||
full_name: fullName.value.trim(),
|
||||
email: cleanEmail,
|
||||
password: cleanPass
|
||||
})
|
||||
console.log('Registro exitoso en Supabase:', regResponse)
|
||||
await authStore.register(cleanEmail, cleanPass, fullName.value.trim())
|
||||
|
||||
analyticsService.logEvent({
|
||||
event_name: 'sign_up',
|
||||
properties: { method: 'email' }
|
||||
})
|
||||
|
||||
console.log('Iniciando sesión automática...')
|
||||
await authStore.login(cleanEmail, cleanPass)
|
||||
|
||||
successMessage.value = '¡Cuenta creada con éxito!'
|
||||
|
||||
setTimeout(() => {
|
||||
const r = authStore.role || 'PASSENGER'
|
||||
navigateByUserRole(r)
|
||||
|
||||
// Delay navigation so user can see the success card
|
||||
setTimeout(() => {
|
||||
navigateByUserRole(authStore.role || 'PASSENGER')
|
||||
}, 1500)
|
||||
|
||||
} catch (error: any) {
|
||||
console.error('Error detallado de registro:', error)
|
||||
errorMessage.value = `Error: ${error.message || 'Error desconocido'}`
|
||||
if (error.message?.includes('User already registered') || error.message?.includes('already exists')) {
|
||||
errorMessage.value = 'El correo ya está registrado.'
|
||||
} else {
|
||||
errorMessage.value = `Error: ${error.message || 'Error desconocido'}`
|
||||
}
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const navigateByUserRole = (role: string) => {
|
||||
const r = role.toUpperCase()
|
||||
if (r === 'ADMIN') router.push('/admin')
|
||||
|
||||
Reference in New Issue
Block a user