mirror of
https://github.com/PretendoNetwork/website.git
synced 2026-08-27 02:56:47 -05:00
fix: fixed redirect to login
This commit is contained in:
@@ -31,7 +31,6 @@ export function getSafeRedirectUrl(input: string | null, baseUrl: string, allowe
|
||||
|
||||
export function useAuthUtils() {
|
||||
const authStore = useAuthStore();
|
||||
const route = useRoute();
|
||||
const config = useRuntimeConfig();
|
||||
const allowedRedirectHosts = computed(() => config.public.redirectHosts.split(' ').map(v => v.trim()).filter(v => v.length > 0));
|
||||
|
||||
@@ -46,11 +45,12 @@ export function useAuthUtils() {
|
||||
external: redirectUrl.external
|
||||
});
|
||||
},
|
||||
async redirectToLogin() {
|
||||
await navigateTo({
|
||||
redirectToLogin(to?: string | undefined) {
|
||||
const target = to ?? useRoute().fullPath;
|
||||
return navigateTo({
|
||||
path: '/account/login',
|
||||
query: {
|
||||
redirect: route.fullPath
|
||||
redirect: target
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
function notAllowed() {
|
||||
return navigateTo('/');
|
||||
import type { RouteLocationNormalizedGeneric } from 'vue-router';
|
||||
|
||||
function notAllowed(to: RouteLocationNormalizedGeneric) {
|
||||
const authUtils = useAuthUtils();
|
||||
return authUtils.redirectToLogin(to.fullPath);
|
||||
}
|
||||
|
||||
export default defineNuxtRouteMiddleware(async (to) => {
|
||||
@@ -10,7 +13,7 @@ export default defineNuxtRouteMiddleware(async (to) => {
|
||||
|
||||
if (to.meta.needsAuth) {
|
||||
if (!meStore.user) {
|
||||
return notAllowed();
|
||||
return notAllowed(to);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user