Add database transaction and pessimistic locking to passkey verification

Merged
JO
7mo ago
+20-7

Description

This PR adds database transaction support and pessimistic locking to the passkey verification process to prevent race conditions and ensure data consistency.

Changes

  • Wrapped the entire passkey verification flow in a database transaction
  • Added pessimistic locking (lockForUpdate()) when retrieving the passkey during verification
  • Modified getPasskey() method to accept an optional $lock parameter to control whether row-level locking is applied
  • All verification steps (validation, updates, and event dispatch) now execute atomically within the transaction

Benefits

  • Race condition prevention: Pessimistic locking ensures that concurrent verification attempts cannot interfere with each other
  • Data consistency: The transaction guarantees that either all verification steps succeed together or none of them do
  • Atomic operations: Passkey updates and event dispatches are guaranteed to happen together, preventing partial state updates

Breaking Changes

None. The getPasskey() method's new $lock parameter is optional and defaults to false, maintaining backward compatibility.

Testing

Existing tests should continue to pass. The transaction and locking behavior is transparent to callers of the VerifyPasskey action.

https://claude.ai/code/session_01PFPpktxKHAfDsoqaiUKakz