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
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import type { H3Event } from 'h3'
|
||||
import type { PublicBooking } from '~~/shared/booking'
|
||||
|
||||
import { normalizeUsername, type UserRole } from '~~/shared/auth'
|
||||
|
||||
@@ -54,6 +55,19 @@ export async function requireRole(event: H3Event, role: UserRole) {
|
||||
return auth
|
||||
}
|
||||
|
||||
export async function requireBookingManager(event: H3Event, booking: Pick<PublicBooking, 'personInChargeId'>) {
|
||||
const auth = await requireAuth(event)
|
||||
|
||||
if (auth.user.role !== 'super_admin' && auth.user.id !== booking.personInChargeId) {
|
||||
throw createError({
|
||||
statusCode: 403,
|
||||
statusMessage: 'You are not allowed to manage this booking'
|
||||
})
|
||||
}
|
||||
|
||||
return auth
|
||||
}
|
||||
|
||||
export async function signInUser(event: H3Event, user: UserAuthRecord, remember: boolean) {
|
||||
await createUserSession(event, {
|
||||
userId: user.id,
|
||||
|
||||
Reference in New Issue
Block a user