【问题标题】:Express.js - TypeError: Cannot read property 'render' of undefinedExpress.js - TypeError:无法读取未定义的属性“渲染”
【发布时间】:2020-04-28 16:23:03
【问题描述】:

在我的 Express.js 后端,当用户想要重置密码时,会通过 Sendgrid 将链接发送到他们的电子邮件,当点击该链接时,用户会收到此错误:

TypeError: Cannot read property 'render' of undefined
    at resetPasswordController.showResetPassword (/root/apps/AskArya-Node.js-Vue.js/Server/app/http/controllers/auth/resetPasswordController.js:11:33)
    at Layer.handle [as handle_request] (/root/apps/AskArya-Node.js-Vue.js/Server/node_modules/express/lib/router/layer.js:95:5)
    at next (/root/apps/AskArya-Node.js-

resetPasswordController 的代码是:

  class resetPasswordController extends controller {
  showResetPassword(req, res) {
    const title = 'بازیابی رمز عبور';
    res.render('home/auth/passwords/reset', {
      recaptcha: this.recaptcha.render(),
      title,
      token: req.params.token
    });
  }

  async resetPasswordProccess(req, res, next) {
    await this.recaptchaValidation(req, res);
    let result = await this.validationData(req);
    if (result) {
      return this.resetPassword(req, res);
    }

    this.back(req, res);
  }

  async resetPassword(req, res) {
    let field = await PasswordReset.findOne({
      $and: [{ email: req.body.email }, { token: req.body.token }]
    });
    if (!field) {
      req.flash('errors', 'اطلاعات وارد شده صحیح نیست لطفا دقت کنید');
      return this.back(req, res);
    }

【问题讨论】:

    标签: node.js api express


    【解决方案1】:

    我相信这个错误来自这一行:

    recaptcha: this.recaptcha.render(),
    

    这是因为 this.recaptcha 为空。 很可能,这段代码是从其他地方复制过来的,这里定义了 this.recaptcha。

    【讨论】:

    • 我之前因为不想用了所以注释掉了,用Recaptcha试试吧。
    猜你喜欢
    • 1970-01-01
    • 2021-07-20
    • 2019-11-24
    • 2016-01-31
    • 2019-02-18
    • 2021-02-17
    • 2020-04-08
    • 2020-07-11
    • 2018-07-14
    相关资源
    最近更新 更多