25 lines
538 B
JavaScript
Executable File
25 lines
538 B
JavaScript
Executable File
export default defineNuxtPlugin((nuxtApp) => {
|
|
const authStore = useAuthStore()
|
|
|
|
const syncAuthState = async () => {
|
|
await authStore.checkAuth()
|
|
}
|
|
|
|
nuxtApp.hook('app:mounted', () => {
|
|
syncAuthState()
|
|
})
|
|
|
|
if (typeof window !== 'undefined') {
|
|
window.addEventListener('pageshow', (event) => {
|
|
if (event.persisted) {
|
|
syncAuthState()
|
|
}
|
|
})
|
|
|
|
document.addEventListener('visibilitychange', () => {
|
|
if (document.visibilityState === 'visible') {
|
|
syncAuthState()
|
|
}
|
|
})
|
|
}
|
|
}) |