Merged in feat/SW-2903-tokens (pull request #2508)
feat(SW-2358): Use personal token if logged in * feat(SW-2903): Use personal token if logged in * Avoid encoding values in cookie * Fix tests Approved-by: Anton Gunnarsson
This commit is contained in:
committed by
Anton Gunnarsson
parent
5d9006bfdc
commit
b35ceafc00
@@ -1,6 +1,7 @@
|
||||
import type { Guest } from "@scandic-hotels/trpc/routers/booking/output"
|
||||
|
||||
import type { SafeUser } from "@/types/user"
|
||||
import type { AdditionalInfoCookieValue } from "../FindMyBooking/AdditionalInfoForm"
|
||||
|
||||
export {
|
||||
ACCESS_GRANTED,
|
||||
@@ -36,13 +37,21 @@ function accessBooking(
|
||||
|
||||
if (guest.lastName?.toLowerCase() === lastName.toLowerCase()) {
|
||||
if (user) {
|
||||
return ERROR_FORBIDDEN
|
||||
} else {
|
||||
const params = new URLSearchParams(cookie)
|
||||
if (
|
||||
params.get("firstName")?.toLowerCase() ===
|
||||
guest.firstName?.toLowerCase() &&
|
||||
params.get("email")?.toLowerCase() === guest.email?.toLowerCase()
|
||||
user.firstName.toLowerCase() === guest.firstName?.toLowerCase() &&
|
||||
user.email.toLowerCase() === guest.email?.toLowerCase()
|
||||
) {
|
||||
return ACCESS_GRANTED
|
||||
} else {
|
||||
return ERROR_FORBIDDEN
|
||||
}
|
||||
} else {
|
||||
const values =
|
||||
cookie && (JSON.parse(cookie) as Partial<AdditionalInfoCookieValue>)
|
||||
if (
|
||||
values &&
|
||||
values.firstName?.toLowerCase() === guest.firstName?.toLowerCase() &&
|
||||
values.email?.toLowerCase() === guest.email?.toLowerCase()
|
||||
) {
|
||||
return ACCESS_GRANTED
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user