🚀 Feat(Core): Migración oficial y total B a Supabase (Auth, DB, APIs) + Eliminación de Backend Python y Fixes Firebase + Soporte Vite Vercel
This commit is contained in:
@ -1,10 +1,8 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { ref, onMounted, watch } from 'vue'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import LoginForm from '@/components/auth/LoginForm.vue'
|
||||
import RegisterForm from '@/components/auth/RegisterForm.vue'
|
||||
import { getGoogleRedirectResult } from '@/firebaseConfig'
|
||||
import { authService } from '@/services/authService'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
|
||||
const isLogin = ref(true)
|
||||
@ -12,33 +10,25 @@ const toggleAuth = () => { isLogin.value = !isLogin.value }
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
const authStore = useAuthStore()
|
||||
const redirectErrorMessage = ref('')
|
||||
const sessionExpiredMessage = ref('')
|
||||
|
||||
// Detectar si fue redirigido por sesión expirada
|
||||
onMounted(async () => {
|
||||
onMounted(() => {
|
||||
if (route.query.reason === 'session_expired') {
|
||||
sessionExpiredMessage.value = 'Tu sesión ha expirado. Por favor, inicia sesión nuevamente.'
|
||||
}
|
||||
})
|
||||
|
||||
try {
|
||||
const result = await getGoogleRedirectResult()
|
||||
if (result) {
|
||||
console.log('Procesando resultado de redirección de Google...')
|
||||
const response = await authService.googleLogin(result.token)
|
||||
authStore.login(response.access_token, response.role, response.full_name)
|
||||
|
||||
const role = response.role.toUpperCase()
|
||||
// Observa cambios en el rol cuando regresa de Google Oauth y lo redirige automáticamente
|
||||
watch(() => authStore.role, (newRole) => {
|
||||
if (authStore.isAuthenticated && newRole) {
|
||||
const role = newRole.toUpperCase()
|
||||
if (role === 'ADMIN') router.push('/admin')
|
||||
else if (role === 'DRIVER') router.push('/driver')
|
||||
else if (role === 'PROMOTER') router.push('/promoter')
|
||||
else router.push('/map')
|
||||
}
|
||||
} catch (e: any) {
|
||||
console.error('Google redirect result error:', e)
|
||||
redirectErrorMessage.value = `Error al volver de Google: ${e.message || 'Error desconocido'}`
|
||||
}
|
||||
})
|
||||
}, { immediate: true })
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@ -85,12 +75,6 @@ onMounted(async () => {
|
||||
{{ sessionExpiredMessage }}
|
||||
</div>
|
||||
|
||||
<!-- Alerta de error en redirección -->
|
||||
<div v-if="redirectErrorMessage" class="redirect-error">
|
||||
<span class="material-icons">warning</span>
|
||||
{{ redirectErrorMessage }}
|
||||
</div>
|
||||
|
||||
<!-- Formularios con transición -->
|
||||
<Transition name="auth-slide" mode="out-in">
|
||||
<LoginForm v-if="isLogin" @toggle="toggleAuth" />
|
||||
|
||||
Reference in New Issue
Block a user