fix: fixed redirect to login
Some checks failed
Build and Publish Docker Image / Build and Publish (amd64) (push) Has been cancelled
Build and Publish Docker Image / Build and Publish (arm64) (push) Has been cancelled

This commit is contained in:
mrjvs
2026-08-15 19:01:25 +02:00
parent 4159d0b7f1
commit f796bc00ec
2 changed files with 10 additions and 7 deletions

View File

@@ -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
}
});
},

View File

@@ -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);
}
}
});