NestJS · Middle · Question 23 of 75
How can a custom validation rule check something asynchronous, like 'email is not taken'?
- 1With
ParseIntPipe - 2Validation decorators can't be async
- ✓Correct answer: With a custom
class-validatorconstraint class (it can be async and use DI withuseContainer), though a unique index is still the real guarantee
Explanation
Async checks improve error messages but have race conditions. The database constraint must catch concurrent duplicates.