gateway
This commit is contained in:
+8
-5
@@ -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' })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user