尝试使用 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 }
})