|
1 | 1 | import type { Route } from 'vue-router'
|
2 | 2 | import { RouteNames } from '@/enums'
|
3 | 3 | import { SessionStorageKeys } from 'sbc-common-components/src/util/constants'
|
4 |
| -import { useNavigation } from '@/composables' |
5 |
| - |
6 |
| -const { goToRoute } = useNavigation() |
7 | 4 |
|
8 | 5 | /** Returns True if route requires authentication, else False. */
|
9 | 6 | function requiresAuth (route: Route): boolean {
|
@@ -41,23 +38,15 @@ function isLoginSuccess (route: Route): boolean {
|
41 | 38 | export default defineNuxtRouteMiddleware( (to) => {
|
42 | 39 | if (isLoginSuccess(to)) {
|
43 | 40 | // this route is to verify login
|
44 |
| - navigateTo({ |
45 |
| - name: RouteNames.SIGN_IN, |
46 |
| - query: { redirect: to.query.redirect } |
47 |
| - }) |
48 |
| - } else { |
49 |
| - if (requiresAuth(to) && !isAuthenticated()) { |
50 |
| - // this route needs authentication, so re-route to login |
51 |
| - navigateTo({ name: RouteNames.LOGIN, query: { redirect: to.fullPath } }) |
52 |
| - // return goToRoute(RouteNames.LOGIN, { redirect: to.fullPath }) |
53 |
| - } else { |
54 |
| - if (isLogin(to) && isAuthenticated()) { |
55 |
| - // this route is to dashboard after login |
56 |
| - navigateTo({ name: RouteNames.DASHBOARD }) |
57 |
| - } else { |
58 |
| - // otherwise just proceed normally |
59 |
| - navigateTo() |
60 |
| - } |
61 |
| - } |
| 41 | + return navigateTo({ name: RouteNames.SIGN_IN, query: { redirect: to.query.redirect } }) |
| 42 | + } |
| 43 | + |
| 44 | + if (requiresAuth(to) && !isAuthenticated()) { |
| 45 | + // this route needs authentication, so re-route to login |
| 46 | + return navigateTo({ name: RouteNames.LOGIN, query: { redirect: to.path } }) |
| 47 | + } |
| 48 | + |
| 49 | + if (isLogin(to) && isAuthenticated()) { |
| 50 | + return navigateTo({ name: RouteNames.DASHBOARD }) |
62 | 51 | }
|
63 | 52 | })
|
0 commit comments