1405/04/17-
This commit is contained in:
+60
-8
@@ -14,6 +14,44 @@ import {
|
||||
setHasFingerPrint
|
||||
} from '@/app/authBoot'
|
||||
import { recoverMobileViewportAfterAuth } from '@/layouts/composables/useMobileScrollReset'
|
||||
import {
|
||||
getDefaultLandingRoute,
|
||||
hasAbshodeTrading,
|
||||
hasHomePage,
|
||||
hasProductShop,
|
||||
} from '@/config/project-profile'
|
||||
|
||||
const GUEST_PUBLIC_ROUTES = ['login', '404', 'about', 'cart'] as const
|
||||
|
||||
function getGuestPublicRoutes(): string[] {
|
||||
const routes: string[] = [...GUEST_PUBLIC_ROUTES]
|
||||
if (hasProductShop()) {
|
||||
routes.push('buyProduct', 'productDetail')
|
||||
}
|
||||
return routes
|
||||
}
|
||||
|
||||
function enforceProjectRouteAccess(
|
||||
to: RouteLocationNormalized,
|
||||
next: NavigationGuardNext
|
||||
): boolean {
|
||||
if (!hasHomePage() && to.name === 'home') {
|
||||
next({ name: getDefaultLandingRoute() })
|
||||
return true
|
||||
}
|
||||
|
||||
if (!hasAbshodeTrading() && to.name === 'gold') {
|
||||
next({ name: getDefaultLandingRoute() })
|
||||
return true
|
||||
}
|
||||
|
||||
if (!hasProductShop() && (to.name === 'buyProduct' || to.name === 'productDetail')) {
|
||||
next({ name: getDefaultLandingRoute() })
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
export function setupRouterGuards() {
|
||||
const userStore = useUserStore()
|
||||
@@ -43,7 +81,7 @@ export function setupRouterGuards() {
|
||||
}
|
||||
|
||||
function goToLogin(to: RouteLocationNormalized, next: NavigationGuardNext) {
|
||||
if (to.name === 'buyProduct' || to.name === 'productDetail' || to.name === 'about' || to.name === 'cart') {
|
||||
if (getGuestPublicRoutes().includes(to.name as string)) {
|
||||
return next()
|
||||
}
|
||||
if (to.name !== 'login') {
|
||||
@@ -52,9 +90,10 @@ export function setupRouterGuards() {
|
||||
return next()
|
||||
}
|
||||
|
||||
function goToHome(to: RouteLocationNormalized, next: NavigationGuardNext) {
|
||||
if (to.name !== 'buyProduct') {
|
||||
return next({ name: 'buyProduct' })
|
||||
function goToLanding(to: RouteLocationNormalized, next: NavigationGuardNext) {
|
||||
const landing = getDefaultLandingRoute()
|
||||
if (to.name !== landing) {
|
||||
return next({ name: landing })
|
||||
}
|
||||
return next()
|
||||
}
|
||||
@@ -64,6 +103,10 @@ export function setupRouterGuards() {
|
||||
clearFingerTimeout()
|
||||
setFingerTimeOut(to)
|
||||
|
||||
if (enforceProjectRouteAccess(to, next)) {
|
||||
return
|
||||
}
|
||||
|
||||
if (isFirst) {
|
||||
isFirst = false
|
||||
|
||||
@@ -83,12 +126,15 @@ export function setupRouterGuards() {
|
||||
}
|
||||
} else {
|
||||
if (to.name == 'login') {
|
||||
goToHome(to, next)
|
||||
return goToLanding(to, next)
|
||||
}
|
||||
if (enforceProjectRouteAccess(to, next)) {
|
||||
return
|
||||
}
|
||||
return next()
|
||||
}
|
||||
} else {
|
||||
if (['login', '404', 'buyProduct', 'productDetail', 'about', 'cart'].includes(to.name as string)) {
|
||||
if (getGuestPublicRoutes().includes(to.name as string)) {
|
||||
return next()
|
||||
}
|
||||
goToLogin(to, next)
|
||||
@@ -97,18 +143,24 @@ export function setupRouterGuards() {
|
||||
if (getFingerPosition()) {
|
||||
if (getToken()) {
|
||||
if (to.name === 'login') {
|
||||
return next({ name: from.name || 'buyProduct' })
|
||||
return next({ name: (from.name as string) || getDefaultLandingRoute() })
|
||||
}
|
||||
if (enforceProjectRouteAccess(to, next)) {
|
||||
return
|
||||
}
|
||||
return next()
|
||||
}
|
||||
|
||||
if (['login', '404', 'buyProduct', 'productDetail', 'about', 'cart'].includes(to.name as string)) {
|
||||
if (getGuestPublicRoutes().includes(to.name as string)) {
|
||||
return next()
|
||||
}
|
||||
return next({ name: 'login' })
|
||||
}
|
||||
|
||||
if (getToken() && !getHasFingerPrint()) {
|
||||
if (enforceProjectRouteAccess(to, next)) {
|
||||
return
|
||||
}
|
||||
next()
|
||||
} else {
|
||||
goToLogin(to, next)
|
||||
|
||||
Reference in New Issue
Block a user