diff --git a/ppr-ui/src/middleware/01.redirect.global.ts b/ppr-ui/src/middleware/01.redirect.global.ts index bf8b5338a..c190088fe 100644 --- a/ppr-ui/src/middleware/01.redirect.global.ts +++ b/ppr-ui/src/middleware/01.redirect.global.ts @@ -1,9 +1,6 @@ import type { Route } from 'vue-router' import { RouteNames } from '@/enums' import { SessionStorageKeys } from 'sbc-common-components/src/util/constants' -import { useNavigation } from '@/composables' - -const { goToRoute } = useNavigation() /** Returns True if route requires authentication, else False. */ function requiresAuth (route: Route): boolean { @@ -41,23 +38,15 @@ function isLoginSuccess (route: Route): boolean { export default defineNuxtRouteMiddleware( (to) => { if (isLoginSuccess(to)) { // this route is to verify login - navigateTo({ - name: RouteNames.SIGN_IN, - query: { redirect: to.query.redirect } - }) - } else { - if (requiresAuth(to) && !isAuthenticated()) { - // this route needs authentication, so re-route to login - navigateTo({ name: RouteNames.LOGIN, query: { redirect: to.fullPath } }) - // return goToRoute(RouteNames.LOGIN, { redirect: to.fullPath }) - } else { - if (isLogin(to) && isAuthenticated()) { - // this route is to dashboard after login - navigateTo({ name: RouteNames.DASHBOARD }) - } else { - // otherwise just proceed normally - navigateTo() - } - } + return navigateTo({ name: RouteNames.SIGN_IN, query: { redirect: to.query.redirect } }) + } + + if (requiresAuth(to) && !isAuthenticated()) { + // this route needs authentication, so re-route to login + return navigateTo({ name: RouteNames.LOGIN, query: { redirect: to.path } }) + } + + if (isLogin(to) && isAuthenticated()) { + return navigateTo({ name: RouteNames.DASHBOARD }) } })