Browse Source

refactor: use useGlobal composable to get token

pull/9294/head
Pranav C 3 months ago
parent
commit
10e478ad6b
  1. 8
      packages/nc-gui/plugins/redirect.ts

8
packages/nc-gui/plugins/redirect.ts

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

Loading…
Cancel
Save