fix: corregir race condition en favoritos con Supabase INITIAL_SESSION

This commit is contained in:
2026-03-04 16:03:11 -05:00
parent c178523c7e
commit ef5955cea2
3 changed files with 41 additions and 17 deletions

View File

@ -1,7 +1,8 @@
<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'
import { ref, computed, watch } from 'vue'
import { useRouter } from 'vue-router'
import { useFavoritesStore } from '@/stores/favorites'
import { useAuthStore } from '@/stores/auth'
import { useI18n } from 'vue-i18n'
import { getImageUrl as utilGetImageUrl } from '@/utils/imageUrl'
import LoadingBranded from '@/components/common/LoadingBranded.vue'
@ -9,6 +10,7 @@ import LoadingBranded from '@/components/common/LoadingBranded.vue'
const router = useRouter()
const { t } = useI18n()
const favoritesStore = useFavoritesStore()
const authStore = useAuthStore()
const selectedFilter = ref('all')
const filters = computed(() => [
@ -20,9 +22,16 @@ const filters = computed(() => [
{ key: 'stops', label: t('navigation.routes'), icon: 'location_on' }, // Reusing navigation.routes or adding a specific one
])
onMounted(async () => {
await favoritesStore.loadFavorites()
})
// Mismo patrón que FavoriteButton: esperar a que Supabase complete INITIAL_SESSION
watch(
() => authStore.isAuthenticated,
(authenticated) => {
if (authenticated) {
favoritesStore.loadFavorites()
}
},
{ immediate: true }
)
function getImageUrl(path?: string) {
return utilGetImageUrl(path, 'business')