diff --git a/src/boot/axios.ts b/src/boot/axios.ts index dbce985..4bc0f14 100644 --- a/src/boot/axios.ts +++ b/src/boot/axios.ts @@ -1,7 +1,7 @@ import axios, { AxiosInstance } from 'axios'; import { boot } from 'quasar/wrappers'; import { StateInterface } from '../store'; -import config from '../config' +import config from '../config'; declare module 'vue/types/vue' { interface Vue { @@ -14,12 +14,13 @@ export default boot(({ Vue, store }) => { Vue.prototype.$axios = axios; axios.defaults.baseURL = config.baseURL; - axios.interceptors.request.use( - config => { - const token = (store.state).user.token; - if (token) { - config.headers['Authorization'] = 'Token ' + token.token; - } - return config; - }); + axios.interceptors.request.use(config => { + const token = (store.state).user.token; + if (token) { + config.headers['Authorization'] = 'Token ' + token.token; + } + return config; + }); }); + +export { axios }; diff --git a/src/boot/login.ts b/src/boot/login.ts index 3373626..ad88e4e 100644 --- a/src/boot/login.ts +++ b/src/boot/login.ts @@ -2,24 +2,28 @@ import { boot } from 'quasar/wrappers'; import { StateInterface } from '../store'; export default boot(({ Vue, router, store }) => { - router.beforeEach((to, from, next) => { - let user = (store.state).user; - - if (to.matched.some(record => { - // permissions is set AND has NO matching permission - return record.meta.permissions !== undefined && - !(record.meta.permissions.filter( - (value: string) => - user.permissions.includes(value) - ).length > 0); - }) - ) { - next({ - path: '/login', - query: { redirect: to.fullPath } - }); - } else { - next(); - } - }) + router.beforeEach((to, from, next) => { + let user = (store.state).user; + console.log('login_boot', user); + if ( + to.matched.some(record => { + // permissions is set AND has NO matching permission + return ( + record.meta.permissions !== undefined && + !( + record.meta.permissions.filter((value: string) => + user.permissions.includes(value) + ).length > 0 + ) + ); + }) + ) { + next({ + path: '/login', + query: { redirect: to.fullPath } + }); + } else { + next(); + } + }); }); diff --git a/src/boot/plugins.ts b/src/boot/plugins.ts index fc0ed43..f8bf787 100644 --- a/src/boot/plugins.ts +++ b/src/boot/plugins.ts @@ -1,12 +1,12 @@ import { boot } from 'quasar/wrappers'; import { RouteConfig } from 'vue-router'; -import { Module } from 'vuex'; +import { Module, Store } from 'vuex'; const config = { // Do not change required Modules !! requiredModules: ['user'], // here you can import plugins. - loadModules: ['plugin1', 'user-plugin'] + loadModules: [] }; // do not change anything here !! @@ -19,7 +19,7 @@ interface ShortCutLink { interface Plugin { name: string; routes: RouteConfig[]; - store?: Module[]; + store?: Map>; mainLink: PluginMainLink; requiredModules: string[]; shortcuts: ShortCutLink[]; @@ -65,7 +65,7 @@ function combineRoutes( target: RouteConfig[], source: RouteConfig[] ): RouteConfig[] { - // iterate first layer e.g. /main, /login etc. + // iterate first layer e.g. /main, / etc. source.forEach((sourceRouteConfig: RouteConfig) => { const targetRouteConfig: RouteConfig | undefined = target.find( (routeConfig: RouteConfig) => { @@ -138,7 +138,7 @@ function loadPlugin( loadedPlugins: LoadedPlugins, modules: string[], plugins: Plugin[], - store: any + store: Store ): LoadedPlugins { modules.forEach(requiredModule => { const plugin = plugins.find(plugin => { @@ -147,10 +147,15 @@ function loadPlugin( if (plugin) { loadedPlugins.routes = combineRoutes(loadedPlugins.routes, plugin.routes); if (plugin.store) { - plugin.store.forEach(store_module => { - // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access - store.registerModule(store_module); + console.log(plugin.store); + console.log(plugin.store.keys()); + plugin.store.forEach((store_plugin, store_namespace) => { + store.registerModule(store_namespace, store_plugin); }); + //.forEach(store_key => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access + //store.registerModule(store_key, plugin.store.get(store_key)); + //}); } loadedPlugins.mainLinks = combineMainLinks( loadedPlugins.mainLinks, diff --git a/src/pages/Login.vue b/src/pages/Login.vue index b36f69f..17dfb51 100644 --- a/src/pages/Login.vue +++ b/src/pages/Login.vue @@ -1,9 +1,8 @@