Files
dticket.tootaio.com/app/middleware/guest.ts
xiaomai cb683d6b3d feat(bookings): restrict management to assigned PIC or super admin
Secure API endpoints with requireBookingManager authorization check
Update confirmation page to prompt for login if unauthorized
Add safe redirect handling to login and guest middleware
2026-05-09 13:28:50 +08:00

21 lines
558 B
TypeScript

import { getDefaultAuthenticatedPath } from '~~/shared/auth'
function getSafeRedirectPath(value: unknown) {
const redirect = Array.isArray(value) ? value[0] : value
return typeof redirect === 'string' && redirect.startsWith('/') && !redirect.startsWith('//')
? redirect
: null
}
export default defineNuxtRouteMiddleware(async (to) => {
const auth = useAuth()
await auth.fetchSession()
if (!auth.user.value) {
return
}
return navigateTo(getSafeRedirectPath(to.query.redirect) || getDefaultAuthenticatedPath(auth.user.value))
})