Cannot read properties of undefined (reading n )

Hello!

I’m having trouble where our users try to verify their email address, it gets verified, however the post verification link that redirects them to our website come with a query payload like this : example.com/verify?supportSignUp=true&supportForgotPassword=true&email=user@email.adr&message=Cannot+read+properties+of+undefined+(reading+‘n’)&success=false&code=unknown

Anyone know why this could be?
Or point me in the direction on how to debug this?

Hi @pulze,

Welcome to the Auth0 Community!

It seems that the error is suggesting that there is bit of code that is trying to read n from a null object.

Could you check to see if you have any piece of code referencing n?

And could you see if redirecting your users to {{ application.callback_domain }} produces a different result?

Thanks,
Rueben

I have found the issue, the template and/or our implementation of it was outdated.
We have a MondgoDB database connected.
The MongoDB verify actions script template goes the following:

function verify (email, callback) {
  const MongoClient = require('mongodb@3.1.4').MongoClient;
  const client = new MongoClient('mongodb://user:pass@localhost');

  client.connect(function (err) {
    if (err) return callback(err);

    const db = client.db('db-name');
    const users = db.collection('users');
    const query = { email: email, email_verified: false };

    users.update(query, { $set: { email_verified: true } }, function (err, result) {
      client.close();

      if (err) return callback(err);
      callback(null, result.result.n > 0);
    });
  });
}

There is the result.result.n is the one throwing the error, while the document update itself runs perfectly, and successfully.

The mongodb@3.1.4 signals that its too old, so i’ve used “mongodb” instead, to get the latest.

The fix was to update the code with the following :

users.updateOne(query, { $set: { email_verified: true } }, function (err, result) {
      client.close();

      if (err) return callback(err);
      callback(null, result.modifiedCount > 0);
    });

TLDR;
update to updateOne, and result.result.n to result.modifiedCount.

Hi @pulze,

Thanks for the update, and I’m glad that you have resolved the issue!

Feel free to reach out to us again if you have any additional questions.

Thanks,
Rueben

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.