feat: configuration to allow guest access

This commit is contained in:
Jannat Patel
2025-02-06 12:14:24 +05:30
parent 49631b6e56
commit ba26826896
10 changed files with 55 additions and 13 deletions

View File

@@ -1,6 +1,7 @@
import { createRouter, createWebHistory } from 'vue-router'
import { usersStore } from './stores/user'
import { sessionStore } from './stores/session'
import { useSettings } from './stores/settings'
let defaultRoute = '/courses'
const routes = [
@@ -218,7 +219,8 @@ let router = createRouter({
router.beforeEach(async (to, from, next) => {
const { userResource } = usersStore()
let { isLoggedIn } = sessionStore()
const { isLoggedIn } = sessionStore()
const { allowGuestAccess } = useSettings()
try {
if (isLoggedIn) {
@@ -227,6 +229,14 @@ router.beforeEach(async (to, from, next) => {
} catch (error) {
isLoggedIn = false
}
if (!isLoggedIn) {
await allowGuestAccess.promise
if (!allowGuestAccess.data) {
window.location.href = '/login'
return
}
}
return next()
})