Meteor 如何使用Accounts.onemailvificationlink?
我对如何使用Meteor 如何使用Accounts.onemailvificationlink?,meteor,meteor-accounts,Meteor,Meteor Accounts,我对如何使用帐户有点困惑。onEmailVerificationLink 这些文件有些模棱两可: 帐户。onEmailVerificationLink(回调) 注册在单击电子邮件验证链接时要调用的函数 在Accounts.sendVerificationEmail发送的电子邮件中。此函数 应该在顶级代码中调用,而不是在Meteor.startup()中调用 “此函数”、回调或Accounts.onemailvificationlink本身的确切含义是什么 无论如何,无论我把东西放在哪里,我总是在
帐户有点困惑。onEmailVerificationLink
这些文件有些模棱两可: 帐户。onEmailVerificationLink(回调) 注册在单击电子邮件验证链接时要调用的函数 在Accounts.sendVerificationEmail发送的电子邮件中。此函数 应该在顶级代码中调用,而不是在Meteor.startup()中调用 “此函数”、回调或
Accounts.onemailvificationlink
本身的确切含义是什么
无论如何,无论我把东西放在哪里,我总是在浏览器控制台上收到以下错误消息:
Accounts.onEmailVerificationLink was called more than once. Only one callback added will be executed.
如果可以,您应该删除accounts:ui包,该包也可以使用它
meteor remove accounts:ui
然后使用回调添加您自己的逻辑
Accounts.onEmailVerificationLink(function(token, done) {
//your own logic
//Accounts.verifyEmail(token, (error){
// if(!error) {
// alert('done!');
// }
//});
});
如果使用集合挂钩(),可以执行以下操作:
Meteor.users.after.update(function (userId, doc, fieldNames, modifier, options) {
if (!!modifier.$set) {
//check if the email was verified
if (modifier.$set['emails.$.verified'] === true) {
//do something
}
}
});
在花了一些时间尝试连接到onMailVerificationLink之后,我发现上面的功能没有那么挑剔。它所指的函数是“onEmailVerificationLink”。它需要在一些高级客户端代码中。 使用以下代码,我可以在验证电子邮件后更改功能:
// Override the method that fires when the user clicks the link in the verification email
// for our own behavior.
Accounts.onEmailVerificationLink((token, done) => {
Accounts.verifyEmail(token, (err) => {
if (err) {
console.log("Error: ", err);
} else {
console.log("Success");
// Do whatever you want to on completion, the
// done() call is the default one.
done();
}
});
});
控制台消息仍会出现,但覆盖的代码会运行。我还将获得
帐户。onEmailVerificationLink被多次调用。只会执行一个添加的回调。
错误,即使Accounts.onemailvificationlink()
函数为空。你知道了吗?我刚刚删除了这个调用,帐户验证仍然有效,所以我想它必须由useraccounts:package处理。不,最后找到了:它在accounts:ui包中(当然…)我不知道这个特定的回调,但不应该在某个时候调用done
?
// Override the method that fires when the user clicks the link in the verification email
// for our own behavior.
Accounts.onEmailVerificationLink((token, done) => {
Accounts.verifyEmail(token, (err) => {
if (err) {
console.log("Error: ", err);
} else {
console.log("Success");
// Do whatever you want to on completion, the
// done() call is the default one.
done();
}
});
});