0

尝试使用 feathers-authentication-management 进行电子邮件确认。我遵循了 Imre Gelens 的教程,该教程基于 Jon Paul Miles 的旧教程。

验证注册和密码重置都在开发中完全工作,但验证在生产中不起作用。在浏览器中我得到:

POST https://www.example.com/authManagement 400 (Bad Request)

验证确实在生产中完全工作。

也许问题是由于我配置了 nginx 代理服务器,但是为什么验证会起作用?

任何见解都值得赞赏。

教程位于: https ://hackernoon.com/setting-up-email-verification-in-feathersjs-ce764907e4f2和 https://blog.feathersjs.com/how-to-setup-email-verification-in-feathersjs -72ce9882e744

这是 authmanagement.service.js

// Initializes the `authmanagement` service on path `/authmanagement`
const authManagement = require('feathers-authentication-management');
const hooks = require('./authmanagement.hooks');
const notifier = require('./notifier');

module.exports = function (app) {

  // Initialize our service with any options it requires
  app.configure(authManagement(notifier(app)));

  // Get our initialized service so that we can register hooks and filters
  const service = app.service('authManagement');

  service.hooks(hooks);
};

authmanagement.hooks 中没有设置任何钩子

那么notifier.js是:

module.exports = function(app) {

function getLink(type, hash) {
  // I don't think we get this far without hitting the error
  // in dev:
    // const url = 'http://xx.xxx.xxx.xxx:nnnn/' + type + '?token=' + hash
  // in prod:
  // env var:  SERVER_CALL="https://www.example.com/"
  const url = process.env.SERVER_CALL + type + '?token=' + hash
  return url
}

function sendEmail(email) {
  return app.service('mailer').create(email).then(function (result) {
    console.log('Sent email', result)
  }).catch(err => {
    console.log('Error sending email', err)
  })
}

return {
  notifier: function(type, user, notifierOptions) {
    let tokenLink
    let email
    switch (type) {
      case 'resendVerifySignup': //sending the user the verification email
        tokenLink = getLink('verify', user.verifyToken)
        email = {
           from: process.env.FROM_EMAIL,
           to: user.email,
           subject: 'Verify Signup',
           html: "<p>You are receiving this email from a registration request on example.com. \
                If you did not make that request, you can safely ignore this message.</p> \
                <p>To complete your registration, follow this link:</p>" + tokenLink + "&email=" + user.email
        }
        return sendEmail(email)
        break

      case 'verifySignup': // confirming verification
        tokenLink = getLink('verify', user.verifyToken)
        email = {
           from: process.env.FROM_EMAIL,
           to: user.email,
           subject: 'Confirm Signup',
           html: 'Thanks for verifying your email'
        }
        return sendEmail(email)
        break

      case 'sendResetPwd':
        tokenLink = getLink('reset', user.resetToken)
        email = {
           from: process.env.FROM_EMAIL,
           to: user.email,
           subject: 'Reset Password',
           html: "<p>You are receiving this email because someone made a request to reset your password. \
                If you did not make that request, you can safely ignore this message.</p> \
                <p>Alternatively, if you do want to reset you password, follow this link:</p>" + tokenLink + "&email=" + user.email
        }
        return sendEmail(email)
        break

      case 'resetPwd':
        tokenLink = getLink('reset', user.resetToken)
        email = {
           from: process.env.FROM_EMAIL,
           to: user.email,
           subject: 'Confirm Reset',
           html: 'Thanks for resetting'
        }
        return sendEmail(email)
        break

      case 'passwordChange':
        email = {}
        return sendEmail(email)
        break

      case 'identityChange':
        tokenLink = getLink('verifyChanges', user.verifyToken)
        email = {}
        return sendEmail(email)
        break

      default:
        break
    }
  }
}
}

nginx 配置的相关位是:

location /authManagement {
        proxy_pass http://nnn.nn.nnn.nnn:pppp;
}

来自客户的电话是:

    var call = "";
    if (process.env.NODE_ENV === "development"){
      call = "http://xx.xxx.xxx.xxx:pppp/authManagement";
    }
    else if (process.env.NODE_ENV === "production"){
      call = "https://www.example.com/authManagement";
    }

    axios.post(call, {
      action: 'sendResetPwd',
      value: { email: emailValue }
     })
4

1 回答 1

0

就此放弃。Feathers 表面上看起来很棒——尤其是在强大的庄园中自动生成服务。但是尝试调试这样的问题会使手动生成 api 变得更加容易。一个很大的吸引力是为您生成电子邮件确认和密码重置基础设施,但实际上并非如此。而且从头开始似乎也更容易。

作为后续:自从放弃 Feathers 后,我在 1 天内完成了电子邮件认证。我花了一个月的时间试图让 Feathers 工作。我原本估计要3天才能完成这项工作。Moses Esan 制作了一个非常好的教程——我在一两个小时内完成了它,花了一天剩下的时间将电子邮件从 Sendgrid 转移到 AWS SES 和一些其他模块。易于调试和修改。全部完成!诚然,所有客户端代码都被重用,只需稍作修改。
这是他的教程,以防它帮助其他人

于 2020-03-26T19:28:33.223 回答