question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

question: Express Request Object In Custom Validator

See original GitHub issue

How do I get the express request object in a custom validator?

@ValidatorConstraint()
class IsPublic implements ValidatorConstraintInterface {
	
	validate(isPublic: boolean, args: ValidationArguments) {
		// I want to use the request object here
		return true;
	}

	defaultMessage(args: ValidationArguments) {
		return "You don't have the right to create a public group";
	}
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:11
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
vlapocommented, Mar 24, 2020

Right now we do not have option to pass additional context (like request object) into validation process.

2reactions
lalalalalukcommented, Apr 15, 2020

i need it too

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to access request object when defining validators as a ...
Hi, I have a use case where I want to load a different set of validators based on the parameter from the URL....
Read more >
Custom validator on object in express-validation
Okay, so there are few problems with your script: Within the custom handler, you are iterating using forEach : Object.keys(value).
Read more >
How to handle request validation in your Express API
You can validate any property in the Express request object, such as query , which contains the URL query string parsed into an...
Read more >
How to perform custom validation in your Express.js app ...
What you can achieve with custom validation · Check if the entity exists in your database · Verify against certain values in Array...
Read more >
Custom validators/sanitizers - express-validator
A custom validator may be implemented by using the chain method .custom() . It takes a validator function. Custom validators may return Promises...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found