Initial commit
This commit is contained in:
22
middleware/auth.ts
Normal file
22
middleware/auth.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { useUserStore } from '@/stores/user'
|
||||
import { useLocalePath } from '#imports'
|
||||
import { useAudioStore } from '~/stores/audio'
|
||||
// @ts-ignore
|
||||
export default defineNuxtRouteMiddleware(() => {
|
||||
const app = useNuxtApp()
|
||||
// @ts-ignore
|
||||
const user = useUserStore(app.$pinia)
|
||||
const localePath = useLocalePath()
|
||||
const audio = useAudioStore()
|
||||
|
||||
if (user.is_login) {
|
||||
// app.$toast.success('Sucessfully logged in!')
|
||||
// FIXME! https://github.com/MeForma/vue-toaster/issues/33
|
||||
} else {
|
||||
// app.$toast.error('Long time not see. Please login again.')
|
||||
// useNuxtApp().$logger.log('You tried to access ' + window.location + '-- This is not possile without login')
|
||||
audio.resetAudioContext()
|
||||
audio.setPlaying(false)
|
||||
return navigateTo(localePath('/auth/login'))
|
||||
}
|
||||
})
|
Reference in New Issue
Block a user