Попытка подтверждения электронной почты с помощью перо-аутентификации-управления. Я следовал учебному пособию Имре Геленса, которое основано на более старом учебном пособии Джона Пола Майлза.
Проверка регистрации и сброс пароля полностью работают в разработке, но проверка не работает в производстве. В браузере я получаю:
POST https://www.example.com/authManagement 400 (Bad Request)
Verify полностью работает в рабочей среде.
Возможно, проблема в моей конфигурации прокси-сервера nginx, но тогда почему Verify будет работать?
Любое понимание приветствуется.
Учебные пособия: https://hackernoon.com/setting-up-email-verification-in-feathersjs-ce764907e4f2 и https://blog.feathersjs.com/how-to-setup-email-verification-in-feathersjs-72ce9882e744
Вот авторизация. 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
Тогда уведомитель. 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 config:
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 }
})