diff --git a/generator/index.js b/generator/index.js index 818342b..6aab130 100644 --- a/generator/index.js +++ b/generator/index.js @@ -26,11 +26,6 @@ module.exports = (api, options) => { ...options, }); - if (options.useTemplateLoader) { - api.render('./templates/TemplateLoader', { - ...options, - }); - } if (options.useAuthorisation) { api.render('./templates/Authorisation', { ...options, diff --git a/generator/templates/Authorisation/src/guards/AuthorisationGuard b/generator/templates/Authorisation/src/guards/AuthorisationGuard new file mode 100644 index 0000000..4389023 --- /dev/null +++ b/generator/templates/Authorisation/src/guards/AuthorisationGuard @@ -0,0 +1,9 @@ +import Vue from 'vue'; + +export default function (to, from, next) { + if (!Vue.prototype.$store.getters['Authorization/isLoggedIn']) { + next({name: 'login'}); + return; + } + next(); +} diff --git a/generator/templates/TemplateLoader/src/templates/Authorisation.vue b/generator/templates/Authorisation/src/templates/Authorisation.vue similarity index 100% rename from generator/templates/TemplateLoader/src/templates/Authorisation.vue rename to generator/templates/Authorisation/src/templates/Authorisation.vue diff --git a/generator/templates/Default/src/App.vue b/generator/templates/Default/src/App.vue index de95cf1..e2ac7df 100644 --- a/generator/templates/Default/src/App.vue +++ b/generator/templates/Default/src/App.vue @@ -1,62 +1,17 @@ - - - diff --git a/generator/templates/Default/src/newmain.js b/generator/templates/Default/src/newmain.js index bed1da0..4999936 100644 --- a/generator/templates/Default/src/newmain.js +++ b/generator/templates/Default/src/newmain.js @@ -14,6 +14,9 @@ import './registerServiceWorker' Vue.prototype.$http = API; window.$http = API; +<%_ if (options.useAuthorisation) { _%> +Vue.prototype.$store = store; +<%_ } _%> <%_ if (options.useCrud) { _%> Vue.use(VuetifyResource); <%_ } _%> diff --git a/generator/templates/Default/src/router.js b/generator/templates/Default/src/router.js index 9e803a1..11a6fc7 100644 --- a/generator/templates/Default/src/router.js +++ b/generator/templates/Default/src/router.js @@ -1,5 +1,8 @@ import Vue from 'vue'; import Router from 'vue-router'; +<%_ if (options.useAuthorisation) { _%> +import AuthorisationGuard from './guards/AuthorisationGuard'; +<%_ } _%> Vue.use(Router); @@ -8,77 +11,80 @@ export default new Router({ base: process.env.BASE_URL, routes: [ { - path: '/', - name: 'home', - component: () => import('@/views/Home'), - }, - { - path: '/403', - name: '403', - component: () => import('./views/PageForbidden.vue'), + path: '', + redirect: {name: 'home'}, }, <%_ if (options.useAuthorisation) { _%> { - path: '/login', - name: 'login', - component: () => import('@/views/Login'), - <%_ if (options.useTemplateLoader) { _%> - meta: { - template: () => import('./templates/Authorisation.vue'), - }, - <%_ } _%> - }, - { - path: '/password/forgotten', - name: 'password.forgotten', - component: () => import('./views/PasswordForgotten.vue'), - <%_ if (options.useTemplateLoader) { _%> - meta: { - template: () => import('./templates/Authorisation.vue'), - }, - <%_ } _%> + path: '', + component: () => import('@/templates/Authorisation'), + children: [ + { + path: '/login', + name: 'login', + component: () => import('@/views/Login'), + }, + { + path: '/password/forgotten', + name: 'password.forgotten', + component: () => import('./views/PasswordForgotten.vue'), + }, + { + path: '/password/reset/:token', + name: 'password.reset', + component: () => import('./views/PasswordReset.vue'), + }, + { + path: '/invitation/accept/:token', + name: 'invitation.accept', + component: () => import('./views/InvitationAccept.vue'), + }, + ] }, + <%_ } _%> { - path: '/password/reset/:token', - name: 'password.reset', - component: () => import('./views/PasswordReset.vue'), - <%_ if (options.useTemplateLoader) { _%> - meta: { - template: () => import('./templates/Authorisation.vue'), - }, + path: '', + <%_ if (options.useAuthorisation) { _%> + beforeEnter: AuthorisationGuard, <%_ } _%> + component: () => import('@/templates/Default'), + children: [ + { + path: '/', + name: 'home', + component: () => import('@/views/Home'), + }, + <%_ if (options.useAuthorisation) { _%> + { + path: '/profile', + name: 'profile', + component: () => import('./views/Profile.vue') + }, + <%_ } _%> + <%_ if (options.useCrud) { _%> + { + path: '/users', + name: 'users', + component: () => import('./views/UserResource.vue') + }, + <%_ } _%> + { + path: '/404', + name: '404', + component: () => import('./views/PageNotFound.vue'), + }, + { + path: '/403', + name: '403', + component: () => import('./views/PageForbidden.vue'), + }, + { + path: '*', + redirect: '/404' + }, + ], }, - { - path: '/invitation/accept/:token', - name: 'invitation.accept', - component: () => import('./views/InvitationAccept.vue'), - <%_ if (options.useTemplateLoader) { _%> - meta: { - template: () => import('./templates/Authorisation.vue'), - }, - <%_ } _%> - }, - { - path: '/profile', - name: 'profile', - component: () => import('./views/Profile.vue') - }, - <%_ } _%> - <%_ if (options.useCrud) { _%> - { - path: '/users', - name: 'users', - component: () => import('./views/UserResource.vue') - }, - <%_ } _%> - { - path: '/404', - name: '404', - component: () => import('./views/PageNotFound.vue'), - }, - { - path: '*', - redirect: '/404' - }, + + ], }); diff --git a/generator/templates/TemplateLoader/src/templates/Default.vue b/generator/templates/Default/src/templates/Default.vue similarity index 100% rename from generator/templates/TemplateLoader/src/templates/Default.vue rename to generator/templates/Default/src/templates/Default.vue diff --git a/generator/templates/TemplateLoader/src/App.vue b/generator/templates/TemplateLoader/src/App.vue deleted file mode 100644 index abe97ce..0000000 --- a/generator/templates/TemplateLoader/src/App.vue +++ /dev/null @@ -1,30 +0,0 @@ - - - diff --git a/prompts.js b/prompts.js index 468d4ee..d31ef21 100644 --- a/prompts.js +++ b/prompts.js @@ -9,12 +9,6 @@ module.exports = [ message: 'Do you want to use a crud system?', default: true, }, - { - name: 'useTemplateLoader', - type: 'confirm', - message: 'Do you want to use a template loader (multiple templates configuration in the router)', - default: true, - }, { name: 'useAuthorisation', type: 'confirm', @@ -39,4 +33,4 @@ module.exports = [ message: 'What is the root API url? (you can change this later)', default: '//example.local/api', } -]; \ No newline at end of file +];