Check if user is authenticated when a page is created

This commit is contained in:
wvffle 2022-08-05 14:20:05 +00:00 committed by Georg Krause
parent 76f6c64708
commit ad41d90a45
2 changed files with 9 additions and 4 deletions

View File

@ -69,9 +69,9 @@ const { width } = useWindowSize()
const showSetInstanceModal = ref(false)
// Fetch user data on startup
if (store.state.auth.authenticated) {
store.dispatch('auth/fetchUser')
}
// NOTE: We're not checking if we're authenticated in the store,
// because we want to learn if we are authenticated at all
store.dispatch('auth/fetchUser')
</script>
<template>

View File

@ -1,4 +1,4 @@
import type { User } from '~/types'
import type { BackendError, User } from '~/types'
import type { Module } from 'vuex'
import type { RootState } from '~/store/index'
import type { RouteLocationRaw } from 'vue-router'
@ -199,6 +199,11 @@ const store: Module<State, RootState> = {
dispatch('moderation/fetchContentFilters', null, { root: true })
])
} catch (error) {
if ((error as BackendError).response?.status === 401) {
logger.info('User is not authenticated')
return
}
logger.error('Error while fetching user profile', error)
}
},