fix(frontend): 'requiresAuth' routes niet meer zonder authenticatie toegankelijk
This commit is contained in:
parent
b8e63e3e34
commit
f94b7808f7
4 changed files with 4 additions and 10 deletions
|
@ -10,10 +10,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const showMenuBar = computed(() => (route.meta as RouteMeta).requiresAuth && auth.authState.user);
|
const showMenuBar = computed(() => (route.meta as RouteMeta).requiresAuth && auth.authState.user);
|
||||||
|
|
||||||
auth.loadUser().catch((_error) => {
|
|
||||||
// TODO Could not load user!
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
|
@ -12,9 +12,11 @@ import App from "./App.vue";
|
||||||
import router from "./router";
|
import router from "./router";
|
||||||
import { aliases, mdi } from "vuetify/iconsets/mdi";
|
import { aliases, mdi } from "vuetify/iconsets/mdi";
|
||||||
import { VueQueryPlugin, QueryClient } from "@tanstack/vue-query";
|
import { VueQueryPlugin, QueryClient } from "@tanstack/vue-query";
|
||||||
|
import authService from "./services/auth/auth-service.ts";
|
||||||
|
|
||||||
const app = createApp(App);
|
const app = createApp(App);
|
||||||
|
|
||||||
|
await authService.loadUser();
|
||||||
app.use(router);
|
app.use(router);
|
||||||
|
|
||||||
const link = document.createElement("link");
|
const link = document.createElement("link");
|
||||||
|
|
|
@ -139,15 +139,14 @@ const router = createRouter({
|
||||||
component: NotFound,
|
component: NotFound,
|
||||||
meta: { requiresAuth: false },
|
meta: { requiresAuth: false },
|
||||||
},
|
},
|
||||||
],
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
router.beforeEach(async (to, _from, next) => {
|
router.beforeEach(async (to, _from, next) => {
|
||||||
// Verify if user is logged in before accessing certain routes
|
// Verify if user is logged in before accessing certain routes
|
||||||
if (to.meta.requiresAuth) {
|
if (to.meta.requiresAuth) {
|
||||||
if (!authState.isLoggedIn.value) {
|
if (!authState.isLoggedIn.value) {
|
||||||
//Next("/login");
|
next("/login");
|
||||||
next();
|
|
||||||
} else {
|
} else {
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,14 +117,11 @@ async function renewToken(): Promise<User | null> {
|
||||||
* End the session of the current user.
|
* End the session of the current user.
|
||||||
*/
|
*/
|
||||||
async function logout(): Promise<void> {
|
async function logout(): Promise<void> {
|
||||||
console.log("LOGOUT");
|
|
||||||
const activeRole = authStorage.getActiveRole();
|
const activeRole = authStorage.getActiveRole();
|
||||||
if (activeRole) {
|
if (activeRole) {
|
||||||
await (await getUserManagers())[activeRole].signoutRedirect();
|
await (await getUserManagers())[activeRole].signoutRedirect();
|
||||||
authStorage.deleteActiveRole();
|
authStorage.deleteActiveRole();
|
||||||
clearAuthState();
|
clearAuthState();
|
||||||
} else {
|
|
||||||
console.log("No active role!!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue