mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 18:15:53 +00:00
Add frontend, backend and CLI
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import * as Sentry from '@sentry/node';
|
||||
import { validationResult } from 'express-validator';
|
||||
|
||||
/**
|
||||
* Validate intended inputs on [req] via express-validator
|
||||
* @param req - express request object
|
||||
* @param res - express response object
|
||||
* @param next - express next function
|
||||
* @returns
|
||||
*/
|
||||
const validate = (req: Request, res: Response, next: NextFunction) => {
|
||||
// express validator middleware
|
||||
|
||||
try {
|
||||
const errors = validationResult(req);
|
||||
if (!errors.isEmpty()) {
|
||||
return res.status(400).json({ errors: errors.array() });
|
||||
}
|
||||
|
||||
return next();
|
||||
} catch (err) {
|
||||
Sentry.setUser(null);
|
||||
Sentry.captureException(err);
|
||||
return res.status(401).send({
|
||||
error: "Looks like you're unauthenticated . Try logging in"
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export default validate;
|
||||
Reference in New Issue
Block a user