Rework to use marbas and authentik instead of poketbase (#1)
Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
15
src/main.ts
15
src/main.ts
@@ -1,4 +1,4 @@
|
||||
import { providePocketBase } from '@/pocketbase';
|
||||
import { useAuthStore } from "@/auth";
|
||||
import { createPinia } from 'pinia';
|
||||
import { createApp } from 'vue';
|
||||
import { createRouter, createWebHistory } from 'vue-router';
|
||||
@@ -10,22 +10,25 @@ import './style.css';
|
||||
initLogger();
|
||||
|
||||
const app = createApp(App);
|
||||
const pb = providePocketBase(app);
|
||||
const pinia = createPinia();
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes,
|
||||
});
|
||||
|
||||
app.use(pinia);
|
||||
|
||||
const authStore = useAuthStore();
|
||||
|
||||
router.beforeEach(async to => {
|
||||
if (!pb.authStore.isValid && to.name !== 'login') {
|
||||
return { name: 'login' };
|
||||
} else if (pb.authStore.isValid && to.name === 'login') {
|
||||
if (to.name === 'callback') {
|
||||
await authStore.login();
|
||||
return { name: 'home' };
|
||||
} else if (!authStore.isLoggedIn) {
|
||||
await authStore.redirect();
|
||||
}
|
||||
});
|
||||
|
||||
app.use(pinia);
|
||||
app.use(router);
|
||||
|
||||
app.mount('#app');
|
||||
|
||||
Reference in New Issue
Block a user