fix: simplify login flow - JWT role instant, no DB queries blocking navigation
This commit is contained in:
@ -40,19 +40,14 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
if (error) throw new Error(error.message)
|
||||
|
||||
if (data.user) {
|
||||
// Establecer sesión y rol inmediatamente desde el JWT (sin esperar BD)
|
||||
// Rol disponible al instante desde el JWT — sin consultas BD bloqueantes
|
||||
userSession.value = data.session
|
||||
// Usar user_metadata como perfil temporal para que el rol esté listo al instante
|
||||
userProfile.value = {
|
||||
id: data.user.id,
|
||||
email: data.user.email,
|
||||
full_name: data.user.user_metadata?.full_name || data.user.email,
|
||||
role: data.user.user_metadata?.role || 'PASSENGER'
|
||||
}
|
||||
// Cargar perfil completo de BD en background (sin bloquear navegación)
|
||||
supabase.from('users').select('*').eq('id', data.user.id).single()
|
||||
.then(({ data: profile }) => { if (profile) userProfile.value = profile })
|
||||
.catch(() => { })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user