mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
Merge pull request #1344 from Tria-plc/alpha
fix: ( fayda ) block one Fayda identity from verifying multiple passe…
This commit is contained in:
@@ -761,6 +761,10 @@ function PassengersForm() {
|
||||
passportExpiryDate: stored.passportExpiryDate || '',
|
||||
passportIssuingAuthority: stored.passportIssuingAuthority || '',
|
||||
faydaVerified: stored.faydaVerified || false,
|
||||
// Restore the identity that verified this passenger, so returning here from a
|
||||
// later step (e.g. Back from /booking/seats) doesn't silently reopen the slot to
|
||||
// an already-used Fayda.
|
||||
faydaSub: stored.faydaSub || undefined,
|
||||
formExpanded: true,
|
||||
};
|
||||
}
|
||||
@@ -873,13 +877,22 @@ function PassengersForm() {
|
||||
if (d?.verified) {
|
||||
const faydaSub: string | undefined = d.sub || d.faydaSub || d.fin;
|
||||
|
||||
// A single Fayda identity can't be reused across two different passengers.
|
||||
const usedByOther = faydaSub && passengers.some(
|
||||
(p, i) => i !== targetIndex && (p as any).faydaSub === faydaSub,
|
||||
);
|
||||
// A single Fayda identity can't be reused across two different passengers. Read the
|
||||
// live form rather than the `passengers` captured when this effect was created — the
|
||||
// snapshot restore repopulates the array as the form initializes.
|
||||
const currentPassengers = watch('passengers') || [];
|
||||
const conflictIndex = faydaSub
|
||||
? currentPassengers.findIndex(
|
||||
(p, i) => i !== targetIndex && (p as any)?.faydaSub === faydaSub,
|
||||
)
|
||||
: -1;
|
||||
|
||||
if (usedByOther) {
|
||||
setFaydaErrors((prev) => ({ ...prev, [targetIndex]: 'This Fayda identity is already linked to another passenger on this booking.' }));
|
||||
if (conflictIndex >= 0) {
|
||||
const conflictName = currentPassengers[conflictIndex]?.name?.trim();
|
||||
setFaydaErrors((prev) => ({
|
||||
...prev,
|
||||
[targetIndex]: `This Fayda ID has already been used to verify Passenger ${conflictIndex + 1}${conflictName ? ` (${conflictName})` : ''}. Each traveller must verify with their own Fayda.`,
|
||||
}));
|
||||
setVerificationStatus((prev) => ({ ...prev, [targetIndex]: 'error' }));
|
||||
} else {
|
||||
// Convert "1980/12/01" → "1980-12-01"
|
||||
@@ -989,6 +1002,13 @@ function PassengersForm() {
|
||||
const emailVal = pick(passengerData.email, user.email);
|
||||
if (emailVal) setValue('passengers.0.email', emailVal);
|
||||
|
||||
// A logged-in, already-verified user occupies slot 0 without going through a fresh
|
||||
// Fayda round trip, so the callback never records their sub on the form. Seed it from
|
||||
// the account here, otherwise the duplicate-identity check has nothing to compare
|
||||
// against and the account holder can re-use their own Fayda on passenger 2.
|
||||
const accountFaydaSub = pick(passengerData.faydaSub, (user as any).faydaSub);
|
||||
if (accountFaydaSub) setValue('passengers.0.faydaSub', accountFaydaSub);
|
||||
|
||||
if (mustVerifyFayda) {
|
||||
// Force the Fayda gate: leave name/DOB/gender empty and keep the form collapsed so the
|
||||
// "Verify with Fayda" screen is shown instead of an editable, pre-filled form.
|
||||
@@ -1103,6 +1123,13 @@ function PassengersForm() {
|
||||
gender: p.gender,
|
||||
nationality: p.nationality,
|
||||
nationalId: p.nationalId,
|
||||
// Carry the verified Fayda identity into the booking store so the duplicate-identity
|
||||
// check still has it if the user comes back to this page from /booking/seats. Without
|
||||
// it the restore path below rebuilds each passenger without a sub, and one Fayda could
|
||||
// then re-verify every passenger. Stripped server-side by the global ValidationPipe
|
||||
// (whitelist: true), so sending it to /passengers/save-details is a no-op there.
|
||||
faydaVerified: p.faydaVerified,
|
||||
faydaSub: p.faydaSub,
|
||||
passportNumber: p.passportNumber,
|
||||
passportCountry: p.passportCountry,
|
||||
passportIssueDate: p.passportIssueDate,
|
||||
|
||||
Reference in New Issue
Block a user