UNPKG

@villedemontreal/jwt-validator

Version:
36 lines 1.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UserValidator = void 0; const constants_1 = require("./config/constants"); const customError_1 = require("./models/customError"); const expressRequest_1 = require("./models/expressRequest"); /** * User Validator */ class UserValidator { /** * Create a new instance of UserValidator * @param {express.Request} req */ constructor(req) { if (!(0, expressRequest_1.isRequestWithJwt)(req)) { throw new Error(`Expecting a request with a '.jwt' here! : ${req.method} ${req.url}`); } this._request = req; } isUser(userId) { return this._request.jwt.sub !== userId; } verifyUser(userId) { if (this._request.jwt.sub !== userId && this._request.jwt.mtlIdentityId !== userId) { // eslint-disable-next-line @typescript-eslint/only-throw-error throw (0, customError_1.createInvalidJwtError)({ code: constants_1.constants.errors.codes.UNAUTHORIZED_ACCESS, target: 'jwt', message: 'Unauthorized access', }); } } } exports.UserValidator = UserValidator; //# sourceMappingURL=userValidator.js.map