feat(#5): use auth
This commit is contained in:
+16
-6
@@ -1,9 +1,10 @@
|
||||
import { createPinia } from 'pinia';
|
||||
import { createApp } from 'vue';
|
||||
import { createRouter, createWebHistory } from 'vue-router';
|
||||
import {createPinia} from 'pinia';
|
||||
import {createApp} from 'vue';
|
||||
import {createRouter, createWebHistory} from 'vue-router';
|
||||
import App from './App.vue';
|
||||
import { initLogger } from './logger';
|
||||
import { routes } from './routes';
|
||||
import {useAuthStore} from './auth';
|
||||
import {initLogger} from './logger';
|
||||
import {routeNames, routes} from './routes';
|
||||
import './style.css';
|
||||
|
||||
initLogger();
|
||||
@@ -18,4 +19,13 @@ const router = createRouter({
|
||||
app.use(pinia);
|
||||
app.use(router);
|
||||
|
||||
app.mount('#app');
|
||||
const authStore = useAuthStore();
|
||||
|
||||
router.beforeEach(to => {
|
||||
if (!to.meta.public && !authStore.isAuthenticated) {
|
||||
return {name: routeNames.home};
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
authStore.bootstrap().finally(() => app.mount('#app'));
|
||||
Reference in New Issue
Block a user