Check if user is authenticated when a page is created
This commit is contained in:
parent
76f6c64708
commit
ad41d90a45
|
@ -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>
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue