|
|
@ -4,8 +4,12 @@ export default defineNuxtPlugin(function (nuxtApp) { |
|
|
|
|
|
|
|
|
|
|
|
const route = router.currentRoute |
|
|
|
const route = router.currentRoute |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// put inside app:created hook to ensure global state is available
|
|
|
|
|
|
|
|
nuxtApp.hooks.hook('app:created', () => { |
|
|
|
|
|
|
|
const { token } = useGlobal() |
|
|
|
|
|
|
|
|
|
|
|
watch( |
|
|
|
watch( |
|
|
|
() => (nuxtApp.$state as ReturnType<typeof useGlobal>)?.token?.value, |
|
|
|
() => token.value ?? (nuxtApp.$state as ReturnType<typeof useGlobal>)?.token?.value, |
|
|
|
async (newToken, oldToken) => { |
|
|
|
async (newToken, oldToken) => { |
|
|
|
try { |
|
|
|
try { |
|
|
|
if (newToken && newToken !== oldToken) { |
|
|
|
if (newToken && newToken !== oldToken) { |
|
|
@ -26,5 +30,7 @@ export default defineNuxtPlugin(function (nuxtApp) { |
|
|
|
console.error(e) |
|
|
|
console.error(e) |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
{ immediate: true }, |
|
|
|
) |
|
|
|
) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|