feat: improve authentication
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -9,15 +9,12 @@ import { useTenantStore } from '@KTXC/stores/tenantStore'
|
||||
import { useUserStore } from '@KTXC/stores/userStore'
|
||||
import { fetchWrapper } from '@KTXC/utils/helpers/fetch-wrapper'
|
||||
import { initializeModules } from '@KTXC/utils/modules'
|
||||
import { createSessionMonitor } from '@KTXC/services/authManager'
|
||||
import App from './App.vue'
|
||||
import router from './router'
|
||||
import vuetify from './plugins/vuetify/index'
|
||||
import '@KTXC/scss/style.scss'
|
||||
|
||||
// Material Design Icons (Vuetify mdi icon set)
|
||||
import '@mdi/font/css/materialdesignicons.min.css'
|
||||
|
||||
// google-fonts
|
||||
import '@fontsource/public-sans/index.css'
|
||||
|
||||
const app = createApp(App)
|
||||
@@ -26,8 +23,6 @@ app.use(pinia)
|
||||
app.use(PerfectScrollbarPlugin)
|
||||
app.use(vuetify)
|
||||
|
||||
// Note: Router is registered AFTER modules are loaded to prevent premature route matching
|
||||
|
||||
const globalWindow = window as typeof window & {
|
||||
[key: string]: unknown
|
||||
}
|
||||
@@ -37,7 +32,6 @@ globalWindow.vue = Vue
|
||||
globalWindow.VueRouter = VueRouterLib
|
||||
globalWindow.Pinia = PiniaLib as unknown
|
||||
|
||||
// Bootstrap initial private UI state (modules, tenant, user) before mounting
|
||||
(async () => {
|
||||
const moduleStore = useModuleStore();
|
||||
const tenantStore = useTenantStore();
|
||||
@@ -48,23 +42,23 @@ globalWindow.Pinia = PiniaLib as unknown
|
||||
moduleStore.init(payload?.modules ?? {});
|
||||
tenantStore.init(payload?.tenant ?? null);
|
||||
userStore.init(payload?.user ?? {});
|
||||
|
||||
// Initialize auth session monitor
|
||||
const sessionMonitor = createSessionMonitor({ onLogout: () => userStore.logout() });
|
||||
sessionMonitor.start();
|
||||
|
||||
// Initialize registered modules (following reference app's bootstrap pattern)
|
||||
// Initialize registered modules
|
||||
await initializeModules(app);
|
||||
|
||||
// Add 404 catch-all route AFTER all modules are loaded
|
||||
// This ensures module routes are registered before the catch-all
|
||||
// Register a catch-all and router
|
||||
router.addRoute({
|
||||
name: 'NotFound',
|
||||
path: '/:pathMatch(.*)*',
|
||||
component: () => import('@KTXC/views/pages/maintenance/error/Error404Page.vue')
|
||||
});
|
||||
|
||||
// Register router AFTER modules are loaded
|
||||
app.use(router);
|
||||
|
||||
await router.isReady();
|
||||
// Home redirect handled by router beforeEnter
|
||||
|
||||
app.mount('#app');
|
||||
} catch (e) {
|
||||
console.error('Bootstrap failed:', e);
|
||||
|
||||
Reference in New Issue
Block a user