Skip to content

Commit 58b7ec7

Browse files
committed
use onBeforeMount in login component instead of beforeEnter on login path
1 parent 0b5eabe commit 58b7ec7

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

adminforth/spa/src/router/index.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ const router = createRouter({
1515
title: 'Login',
1616
customLayout: true
1717
},
18-
beforeEnter: async (to, from, next) => {
19-
if(localStorage.getItem('isAuthorized') === 'true') {
20-
// check if url has next=... and redirect to it
21-
console.log('to.query', to.query)
22-
if (to.query.next) {
23-
next(to.query.next.toString())
24-
} else {
25-
next({name: 'home'});
26-
}
27-
} else {
28-
next()
29-
}
30-
}
18+
// beforeEnter: async (to, from, next) => {
19+
// if(localStorage.getItem('isAuthorized') === 'true') {
20+
// // check if url has next=... and redirect to it
21+
// console.log('to.query', to.query)
22+
// if (to.query.next) {
23+
// next(to.query.next.toString())
24+
// } else {
25+
// next({name: 'home'});
26+
// }
27+
// } else {
28+
// next()
29+
// }
30+
// }
3131
},
3232
{
3333
path: '/resource/:resourceId',

adminforth/spa/src/views/LoginView.vue

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,19 @@
113113
<script setup>
114114
115115
import { getCustomComponent } from '@/utils';
116-
import { onMounted, ref, computed } from 'vue';
116+
import { onBeforeMount, onMounted, ref, computed } from 'vue';
117117
import { useCoreStore } from '@/stores/core';
118118
import { useUserStore } from '@/stores/user';
119119
import { IconEyeSolid, IconEyeSlashSolid } from '@iconify-prerendered/vue-flowbite';
120120
import { callAdminForthApi, loadFile } from '@/utils';
121-
import { useRouter } from 'vue-router';
121+
import { useRoute, useRouter } from 'vue-router';
122122
import { Button, Checkbox } from '@/afcl';
123123
124124
const passwordInput = ref(null);
125125
const usernameInput = ref(null);
126126
const rememberMeValue= ref(false);
127127
128+
const route = useRoute();
128129
const router = useRouter();
129130
const inProgress = ref(false);
130131
@@ -139,6 +140,18 @@ const backgroundPosition = computed(() => {
139140
return coreStore.config?.loginBackgroundPosition || '1/2';
140141
});
141142
143+
onBeforeMount(() => {
144+
if (localStorage.getItem('isAuthorized') === 'true') {
145+
// if route has next param, redirect
146+
// coreStore.fetchMenuAndResource();
147+
if (route.query.next) {
148+
router.push(route.query.next.toString());
149+
} else {
150+
router.push({ name: 'home' });
151+
}
152+
}
153+
})
154+
142155
onMounted(async () => {
143156
if (coreStore.config?.demoCredentials) {
144157
const [username, password] = coreStore.config.demoCredentials.split(':');

0 commit comments

Comments
 (0)