Merged in fix/access-booking-fixes (pull request #1550)

fix: add some more informative messages when booking cant be accessed

Approved-by: Chuma Mcphoy (We Ahead)
This commit is contained in:
Christian Andolf
2025-03-17 14:54:37 +00:00
4 changed files with 23 additions and 5 deletions

View File

@@ -40,7 +40,7 @@ export default function AdditionalInfoForm({
confirmationNumber,
lastName,
}).toString()
document.cookie = `bv=${value}; Path=/; Max-Age=30; Secure; SameSite=Strict`
document.cookie = `bv=${value}; Path=/; Max-Age=600; Secure; SameSite=Strict`
router.refresh()
}

View File

@@ -26,6 +26,12 @@ export default function FindMyBooking() {
const intl = useIntl()
const lang = useLang()
const form = useForm<FindMyBookingFormSchema>({
defaultValues: {
confirmationNumber: "",
firstName: "",
lastName: "",
email: "",
},
resolver: zodResolver(findMyBookingFormSchema),
mode: "all",
criteriaMode: "all",
@@ -36,7 +42,7 @@ export default function FindMyBooking() {
onSuccess: (result) => {
const values = form.getValues()
const value = new URLSearchParams(values).toString()
document.cookie = `bv=${encodeURIComponent(value)}; Path=/; Max-Age=30; Secure; SameSite=Strict`
document.cookie = `bv=${encodeURIComponent(value)}; Path=/; Max-Age=600; Secure; SameSite=Strict`
router.push(
`/${lang}/hotelreservation/my-stay/${encodeURIComponent(result.refId)}`
)

View File

@@ -35,11 +35,11 @@ const findMyBookingFormSchema = additionalInfoFormSchema.extend({
confirmationNumber: z
.string()
.trim()
.regex(/^[0-9]+(-[0-9])?$/, {
message: "Invalid booking number",
})
.min(1, {
message: "Booking number is required",
})
.regex(/^[0-9]+(-[0-9])?$/, {
message: "Invalid booking number",
}),
lastName: z.string().trim().max(250).min(1, {
message: "Last name is required",

View File

@@ -25,12 +25,18 @@ function accessBooking(
return ACCESS_GRANTED
}
} else {
console.warn(
"Access to booking not granted due to anonymous user attempting accessing to logged in booking"
)
return ERROR_UNAUTHORIZED
}
}
if (guest.lastName === lastName) {
if (user) {
console.warn(
"Access to booking not granted due to logged in user attempting access to anonymous booking"
)
return ERROR_FORBIDDEN
} else {
const params = new URLSearchParams(cookie)
@@ -40,11 +46,17 @@ function accessBooking(
) {
return ACCESS_GRANTED
} else {
console.warn(
"Access to booking not granted due to incorrect cookie values"
)
return ERROR_BAD_REQUEST
}
}
}
console.warn(
"Access to booking not granted due to anonymous user attempting access with incorrect lastname"
)
return ERROR_NOT_FOUND
}