fix: pwa, firebase and auth initial load issues

This commit is contained in:
2026-04-28 14:50:13 +05:00
parent 669d8571ae
commit fad9cacd3e
8 changed files with 72 additions and 23 deletions
+22 -5
View File
@@ -119,10 +119,19 @@ definePageMeta({
const auth = useAuth()
const user = computed(() => auth.user)
const authFetch = (url, opts = {}) => $fetch(url, {
...opts,
headers: { Authorization: `Bearer ${auth.token.value}`, ...opts.headers }
})
const authFetch = async (url, opts = {}) => {
try {
return await $fetch(url, {
...opts,
headers: { Authorization: `Bearer ${auth.token.value}`, ...opts.headers }
})
} catch (error) {
if (error.response?.status === 401) {
auth.logout()
}
throw error
}
}
const canvases = ref([])
const userGroups = ref([])
@@ -287,5 +296,13 @@ const getGroupName = (groupId) => {
return group?.name || 'Unknown Group'
}
onMounted(loadData)
onMounted(() => {
if (auth.isAuthenticated.value) {
loadData()
}
})
watch(() => auth.isAuthenticated.value, (isAuth) => {
if (isAuth) loadData()
})
</script>