I have the following:

Template.joinTemplate.events({
"submit #Signup-Form": function(event, template) {
    event.preventDefault();
    var email = template.find('#Email').value;
    Accounts.createUser({
        username: template.find('#Email').value,
        emails: {
            address: template.find('#Email').value
        },
        password: template.find('#Password').value,
        profile: {
            firstname: template.find("#Firstname").value,
            lastname: template.find("#Lastname").value

        }
    }, function(error) {
        if (error) {
            // Deal with errors
        } else {
            Accounts.sendVerificationEmail(this.userId, email);
            Router.go('/');

        }
    });
}
});

But get the following error:

 Error logging in with token: Error: You've been logged out by the server. Please login again. [403] debug.js:41
Exception in delivering result of invoking 'createUser': TypeError: Object #<Object> has no method 'sendVerificationEmail'
    at http://localhost:3000/client/views/application/authentication/join_template.js?0ca175e5dc0f3b4596ed33e260d5636f8f9cc69b:28:26
    at http://localhost:3000/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:801:19
    at loggedInAndDataReadyCallback (http://localhost:3000/packages/accounts-base.js?efdcc57c69f7e2ccbb61f1e963da216b1729ac72:455:5)
    at null._callback (http://localhost:3000/packages/meteor.js?2b578107b8239ff9bc64200e6af2a24001461b30:801:22)
    at _.extend._maybeInvokeCallback (http://localhost:3000/packages/livedata.js?418d88f2513ae6bf0ff1447759a5c590923456bd:3502:12)
    at _.extend.receiveResult (http://localhost:3000/packages/livedata.js?418d88f2513ae6bf0ff1447759a5c590923456bd:3522:10)
    at _.extend._livedata_result (http://localhost:3000/packages/livedata.js?418d88f2513ae6bf0ff1447759a5c590923456bd:4452:9)
    at onMessage (http://localhost:3000/packages/livedata.js?418d88f2513ae6bf0ff1447759a5c590923456bd:3376:12)
    at http://localhost:3000/packages/livedata.js?418d88f2513ae6bf0ff1447759a5c590923456bd:2705:11
    at Array.forEach (native) 

I have all accounts-base, accounts-ui, accounts-password installed.

Not sure what I'm doing wrong :(

有帮助吗?

解决方案

As you can read in the documentation, Accounts.sendVerificationEmail is only available on the server, and you're trying to use it on the client.

I'm not sure that you can use the Accounts.onCreateUser function to send verification emails: in this function, the user has not been added to the Meteor.users collection yet, and I guess Accounts.sendVerificationEmail requires the user to be in that collection. I don't know the best way to solve this, but you can always use a cursor selecting all users, and then observe users added to the collection (although, this is not a good solution).

It's not enough to use the sendVerificationEmail field in the Accounts.config function?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top