Skip to content

Commit 7a1d625

Browse files
committed
add next param support for signup
1 parent 653f19f commit 7a1d625

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

adminforth/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

adminforth/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "adminforth",
3-
"version": "1.5.8-next.20",
3+
"version": "1.5.8-next.21",
44
"description": "OpenSource Vue3 powered forth-generation admin panel",
55
"main": "dist/index.js",
66
"module": "dist/index.js",

adminforth/plugins/open-signup/custom/SignupPage.vue

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133

134134

135135
<script setup lang="ts">
136-
import { onMounted, ref, computed, Ref } from 'vue';
136+
import { onMounted, ref, computed, Ref, onBeforeMount } from 'vue';
137137
import { useCoreStore } from '@/stores/core';
138138
import { useUserStore } from '@/stores/user';
139139
import { callAdminForthApi, loadFile, applyRegexValidation } from '@/utils';
@@ -230,7 +230,36 @@ const passwordConstraints: Ref<{
230230
validation: '',
231231
});
232232
233+
// implement something similar to beforeEnter
234+
// beforeEnter: async (to, from, next) => {
235+
// if(localStorage.getItem('isAuthorized') === 'true') {
236+
// // check if url has next=... and redirect to it
237+
// console.log('to.query', to.query)
238+
// if (to.query.next) {
239+
// next(to.query.next.toString())
240+
// } else {
241+
// next({name: 'home'});
242+
// }
243+
// } else {
244+
// next()
245+
// }
246+
// }
247+
248+
onBeforeMount(() => {
249+
if (localStorage.getItem('isAuthorized') === 'true') {
250+
// if route has next param, redirect
251+
coreStore.fetchMenuAndResource();
252+
if (route.query.next) {
253+
router.push(route.query.next.toString());
254+
} else {
255+
router.push({ name: 'home' });
256+
}
257+
}
258+
})
259+
233260
onMounted(async () => {
261+
262+
234263
await coreStore.getPublicConfig();
235264
// getPasswordConstraints
236265
passwordConstraints.value = await callAdminForthApi({

adminforth/spa/src/stores/user.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const useUserStore = defineStore('user', () => {
1010
const isAuthorized = ref(false);
1111

1212
function authorize() {
13+
// syncing isAuthorized allows us to use navigation guards without waiting for user api response
1314
isAuthorized.value = true;
1415
localStorage.setItem('isAuthorized', 'true');
1516
}
@@ -21,9 +22,14 @@ export const useUserStore = defineStore('user', () => {
2122

2223
async function finishLogin() {
2324
const coreStore = useCoreStore();
24-
authorize(); // TODO not sure we need this approach with localStorage
25+
authorize();
2526
reconnect();
26-
await router.push('/');
27+
// if next param in route, redirect to it
28+
if (router.currentRoute.value.query.next) {
29+
await router.push(router.currentRoute.value.query.next.toString());
30+
} else {
31+
await router.push('/');
32+
}
2733
await router.isReady();
2834
await coreStore.fetchMenuAndResource();
2935
}

0 commit comments

Comments
 (0)