Files
nlcc-itinerary/middleware/auth.ts
Joshua Ryder d8fd24c6b1 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>
2025-11-06 10:29:38 -05:00

11 lines
347 B
TypeScript

export default defineNuxtRouteMiddleware(async (to, from) => {
if (import.meta.server) return
const { data } = await useFetch('/api/auth/verify')
if (!data.value?.authenticated) {
// Preserve the original URL so user can be redirected back after login
return navigateTo(`/login?redirect=${encodeURIComponent(to.fullPath)}`)
}
})