Exception in delivering result of invoking 'createUser': TypeError: _accountsBase.Accounts.sendVerificationEmail is not a function


#1

So I’ve been stuck for three hours now on this seemingly simple thing, sending a verification email to a user on registration.

Actual error is:

Exception in delivering result of invoking ‘createUser’: TypeError: _accountsBase.Accounts.sendVerificationEmail is not a function

/imports/api/users/methods.js

import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';

export const userSendVerificationEmail = function() {
  let userId = Meteor.userId();
  if ( userId ) {
    return Accounts.sendVerificationEmail( userId );
  }
};

I’m not sure what I need to change since I’m following the example here: https://github.com/meteor/todos/blob/82b493da1893d8e5d6bca60f212cdab841f31903/imports/startup/server/reset-password-email.js


#2

did u try wrapping it in a isServer call, i believe sendVerificationEmail is a server only function


#3

Now it looks like this, no error but no email sending or console output in my terminal either.

import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';

export const userSendVerificationEmail = function() {
  let userId = Meteor.userId();
  if (userId && Meteor.isServer) {
    console.log("Sending");
    return Accounts.sendVerificationEmail( userId );
  }
};

Any other suggestions?


#4

if you get no console output its not executing :o

try doing deleting the userId condition and check if you at least get the console.log statement in your terminal


#5

I removed the userId condition and it’s still not working.

Maybe a Foobar example of a simple component calling a method would be enough for me to grok this lol.

Under what file path should this method be? It’s currently in: /imports/api/users/methods.js


#6

path of the method is fine as long as you also import it to the server.

By putting it there you are declaring it on the client…so you have to also import it to the server (example app uses register-api.js) to do so.

Show the code where you are calling the method


#7

This entire thing I’m working is open source, maybe you can take a peek and see where I dun goofed?

Error is:

Uncaught Error: 
Cannot find module '../../api/users/server/methods.js'

https://github.com/nanote-io/nanote-web/blob/master/imports/ui/pages/RegisterPage.jsx#L4

Is it because I can’t import a file that’s in a folder called Server? I’m super confused. :frowning:


#8

methods.js should not be in a server folder…else it is not defined on the client.

Pull it out of the server folder then if your root/server/main.js import the methods.js file


#9

If I import the method file in root/server/main.js how do I call it from RegisterPage.jsx? I need to invoke the Meteor method from the component.


#10

Import method name if the file you want to use it in

import { userSendVerificationEmail } from '../../api/users/methods.js';

then call it

userSendVerificationEmail.call


#11

I just pushed some changes to the repo based on your advice, no more crashes, but it still isn’t sending the email or showing me the console output for the Meteor.isServer conditional. :frowning:

https://github.com/nanote-io/nanote-web/commit/a52b6f1582c710f46f7052119d7052e62f7c2b1b

Thanks so much for the help here, I feel like I’m super close lol.


#12

did you try taking userId out of the isServer condition after you made your other changes?


#13

I need that userId to send the verification email.


#14

ya but you can just get it when u are on the server , i.e. after the condition…so jsut try removing it to see if the method gets executed on the server…thats the main issue right now


#15

Removed the conditional, still no terminal output for console.log. :frowning:


#16

the problem is that u are using a normal function not a method…so it will not work on the server…

either use the ‘old’ way of

Meteor.methods({
 'userSendVerificationEmail': function(){
 //do method stuff here
}
})

or look at wrapping it your function with the validated method package (recommended in the guide)


#17

Stupid question, but did you set MAIL_URL?


#18

It’s working! Making notes here on where I screwed up, looks like I’m just going to use ValidatedMethod. :smiley: