diff --git a/src/components.d.ts b/src/components.d.ts index e2ccd99..8f41a70 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -29,6 +29,8 @@ declare module 'vue' { NConfigProvider: typeof import('naive-ui')['NConfigProvider'] NDataTable: typeof import('naive-ui')['NDataTable'] NDialogProvider: typeof import('naive-ui')['NDialogProvider'] + NDrawer: typeof import('naive-ui')['NDrawer'] + NDrawerContent: typeof import('naive-ui')['NDrawerContent'] NDynamicTags: typeof import('naive-ui')['NDynamicTags'] NForm: typeof import('naive-ui')['NForm'] NFormItem: typeof import('naive-ui')['NFormItem'] diff --git a/src/main.ts b/src/main.ts index ecf0080..5affb44 100644 --- a/src/main.ts +++ b/src/main.ts @@ -36,6 +36,12 @@ router.beforeEach((to, from, next) => { title = `${to.meta.title} - ${title}` document.title = title + + const isAuthenticated = useAccountStore().isAuthenticated() + const isAuthRequired = to.meta.authRequired ?? true + if (isAuthRequired && !isAuthenticated) + next({ path: '/account/login' }) + next() }) enableMocking().then(() => app.mount('#app')) diff --git a/src/pages/Account/login.vue b/src/pages/Account/login.vue index 6790a4d..10c2e8c 100644 --- a/src/pages/Account/login.vue +++ b/src/pages/Account/login.vue @@ -51,6 +51,7 @@ const rules: FormRules = { meta: title: Login layout: auth + authRequired: false