const verifyToken = function (token) { return Bluebird.try(() => { const dirPath = path.join(__dirname, "..", "cert"); const fileName = process.env.AUTH_TOKEN_PUBLIC_KEY; if (!fileName) { console.error("auth token file path not found, reason .env is not set"); throw CustomError._500(errors.AUTH_TOKEN_PUBLIC_KEY_NOT_FOUND.CODE); } return fs.readFileAsync(dirPath + "/" + fileName); }).then((publicKey) => { return jwt.verifyAsync(token, publicKey, { algorithms: ["RS512"] }); }).catch((error) => { console.error("Error while verifying auth token ", error); throw CustomError._401(errors.AUTH_TOKEN.NOT_VALID.CODE, errors.AUTH_TOKEN.NOT_VALID.MESSAGE); }); }