This commit is contained in:
2025-12-21 17:22:27 +03:30
parent 80fe9168b6
commit 7fc6918ded
11 changed files with 160 additions and 70 deletions
+8 -5
View File
@@ -62,6 +62,9 @@ export function setEnableAuthenticate() {
function goToLogin(to: RouteLocationNormalized, next: NavigationGuardNext) {
if (to.name === 'buyProduct') {
return next() // Allow access to buyProduct without login
}
if (to.name !== 'login') {
return next({ name: 'login' }) // Redirect to login
} else {
@@ -135,9 +138,9 @@ router.beforeEach(async (to, from, next) => {
return next()
}
} else {
// If no token, handle redirect to login or allow access to login or 404
if (['login', '404'].includes(to.name as string)) {
return next() // Allow access to login or 404
// If no token, handle redirect to login or allow access to login, 404, or buyProduct
if (['login', '404', 'buyProduct'].includes(to.name as string)) {
return next() // Allow access to login, 404, or buyProduct
}
goToLogin(to, next) // Redirect to login if no token
}
@@ -153,8 +156,8 @@ router.beforeEach(async (to, from, next) => {
return next() // Proceed to the intended route
} else {
// If no token, ensure proper redirection to login or 404
if (['login', '404'].includes(to.name as string)) {
return next() // Allow access to login or 404
if (['login', '404', 'buyProduct'].includes(to.name as string)) {
return next() // Allow access to login, 404, or buyProduct
}
return next({ name: 'login' })
}