如何在注册Meteor后创建没有自动登录的用户

sko*_*ozz 2 account hook login meteor

我正在构建一个Meteor应用程序,我需要在用户创建帐户后删除Meteor的自动登录.

我正在使用UI的帐户密码和帐户条目(可选).

任何的想法?谢谢.

bou*_*ani 9

这是通过电子邮件登录的简单解决方案,它在用户创建后停用自动登录并拒绝以后登录,直到验证电子邮件地址:

if (Meteor.isServer) {

    Accounts.validateLoginAttempt(function(attemptInfo) {

        if (attemptInfo.type == 'resume') return true;

        if (attemptInfo.methodName == 'createUser') return false;

        if (attemptInfo.methodName == 'login' && attemptInfo.allowed) {
            var verified = false;
            var email = attemptInfo.methodArguments[0].user.email;
            attemptInfo.user.emails.forEach(function(value, index) {
                if (email == value.address && value.verified) verified = true;
            });
            if (!verified) throw new Meteor.Error(403, 'Verify Email first!');
        }

        return true;
    });

}
Run Code Online (Sandbox Code Playgroud)