From d8fd24c6b1462b00a5ed152a4fa419e701967daf Mon Sep 17 00:00:00 2001 From: Joshua Ryder Date: Thu, 6 Nov 2025 10:29:38 -0500 Subject: [PATCH] fix: Preserve redirect URL in auth middleware for protected pages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Auth middleware now includes redirect parameter when sending to login - Users attempting to access protected pages are redirected back after login - Works seamlessly with logout flow: logout from /admin → login → back to /admin - Ensures consistent behavior across all protected routes This fixes the issue where logging out from admin pages would redirect to login but not preserve the original page, preventing users from returning to their admin workflow after re-authentication. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- middleware/auth.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/middleware/auth.ts b/middleware/auth.ts index 805379f..47baaa6 100644 --- a/middleware/auth.ts +++ b/middleware/auth.ts @@ -2,8 +2,9 @@ export default defineNuxtRouteMiddleware(async (to, from) => { if (import.meta.server) return const { data } = await useFetch('/api/auth/verify') - + if (!data.value?.authenticated) { - return navigateTo('/login') + // Preserve the original URL so user can be redirected back after login + return navigateTo(`/login?redirect=${encodeURIComponent(to.fullPath)}`) } })