1
votes

I'm trying to implement a user registration system, on android with node as my backend server.

I'm using Node 4.4.5, on localhost, and using the package "email-verification" - https://www.npmjs.com/package/email-verification

So on request from android, a confirmation email with a verification link is sent, which is working fine.

When the link is clicked, a GET request is made, which confirms the user, adds it to the MongoDB database, and a JSON response is sent.

An email is sent to the user that the account is confirmed.

After sending the confirmation email, the server crashes.

Here's my code--

router.get('/email-verification/:URL', function(req, res, next){
var url = req.params.URL;
console.log('email-verify-start');

nev.confirmTempUser(url, function(err, user) {

    console.log('error is :' + err);
    if (user) {
        nev.sendConfirmationEmail(user.email, function(err, info) {
            if (err) {
                console.log('sending_conf_email_failed');
                return res.json({'email': 'sending_conf_email_failed'});
            }

            console.log('user_confirmed');
            res.json({
                'email': 'user_confirmed'
            });

            console.log('Done, and confirmed');
        });
    } else {
        console.log('conf_temp_ser_failed');
        return res.json({'email': 'conf_temp_ser_failed'});
    }
});
});

And here's my log--

error is :null
user_confirmed
Done, and confirmed
GET /register/email-verification/SfC9VlnUv91RkFBHDURIbHodnYme0RdfbTYBj0I4oXyywrpW 200 5177.724 ms - 26

h:\myapp\coep_updates\node_modules\email-verification\node_modules\nodemailer\node_modules\nodemailer-smtp-transport\src\smtp-transport.js:136
return callback(null, info);
^

TypeError: callback is not a function
at h:\myapp\coep_updates\node_modules\email-verification\node_modules\nodemailer\node_modules\nodemailer-smtp-transport\src\smtp-transport.js:136:20
at h:\myapp\coep_updates\node_modules\email-verification\node_modules\nodemailer\node_modules\nodemailer-smtp-transport\node_modules\smtp-connection\src\smtp-connection.js:279:20
at SMTPConnection._actionStream (h:\myapp\coep_updates\node_modules\email-verification\node_modules\nodemailer\node_modules\nodemailer-smtp-transport\node_modules\smtp-connection\src\smtp-connection.js:966:16)
at SMTPConnection.<anonymous> (h:\myapp\coep_updates\node_modules\email-verification\node_modules\nodemailer\node_modules\nodemailer-smtp-transport\node_modules\smtp-connection\src\smtp-connection.js:594:14)
at SMTPConnection._processResponse (h:\myapp\coep_updates\node_modules\email-verification\node_modules\nodemailer\node_modules\nodemailer-smtp-transport\node_modules\smtp-connection\src\smtp-connection.js:516:16)
at SMTPConnection._onData (h:\myapp\coep_updates\node_modules\email-verification\node_modules\nodemailer\node_modules\nodemailer-smtp-transport\node_modules\smtp-connection\src\smtp-connection.js:353:10)
at emitOne (events.js:77:13)
at TLSSocket.emit (events.js:169:7)
at readableAddChunk (_stream_readable.js:153:18)
at TLSSocket.Readable.push (_stream_readable.js:111:10)
at TLSWrap.onread (net.js:531:20)

Process finished with exit code 1

Till the server crashes, everything's working fine. I receive all emails and responses are sent properly, I even see the JSON response {"email":"user_confirmed"} on my browser. The only problem is that the server crashes afterwards.

EDIT 1

I tried adding return statements-- Still the same problem. I added them here--

return res.json({
                'email': 'user_confirmed'
            });

I also tried adding a return--

res.json({
            'email': 'user_confirmed'
        });
return;

No luck till now...

EDIT 2

Ok. so this is actually an open issue on GitHUB, this is reported as a bug.

https://github.com/whitef0x0/node-email-verification/issues/44

2
i am also having the same problem.. and i wasn't able to resolve the issue as mentioned in the github.. could you please tell me the file in which the line no 340 is to be changed?Sahil Chauhan
same issue @Parag Verma, wasnt able to solve even through github solution..... it would be great if you could help. thankskRAk3N
@kRAk3N Please see my answerParag Verma
thanks.. it workedkRAk3N

2 Answers

2
votes

So, I tried the GitHUB the solution this way and it is now working flawlessly, even though an official fix is not released...

In the source folder of the module, in the file 'index.js' -->

Go to line 340 -- 

You'll see this line

callback = options.shouldSendConfirmation;

Change it to -->

callback = function(){};

Hope this helps...

0
votes

You could change your nev.sendConfirmationEmail method to include the callback as the third argument:

nev.sendConfirmationEmail(user.email, function(err, info) {
    if (err) {
        console.log('sending_conf_email_failed');
        return res.json({'email': 'sending_conf_email_failed'});
    }

    console.log('user_confirmed');
    res.json({
        'email': 'user_confirmed'
    });

    console.log('Done, and confirmed');
}, function(){});