fix: Preserve redirect URL in auth middleware for protected pages

- 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 <noreply@anthropic.com>
This commit is contained in:
2025-11-06 10:29:38 -05:00
parent 160a4e58b3
commit d8fd24c6b1

View File

@@ -4,6 +4,7 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
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)}`)
}
})