strongloop / loopback

LoopBack makes it easy to build modern applications that require complex integrations.
http://loopback.io
Other
13.23k stars 1.2k forks source link

Undefined is not a function at normalizeEmailCase when looking up users by multiple email addresses #2077

Closed mrfelton closed 7 years ago

mrfelton commented 8 years ago

Try the following:

var emails = [
  'example1@example.com',
  'example2@example.com',
];
app.models.User.find({
      where: {
        email: {
          inq: emails
        }
      },
    });

Results in error:

undefined is not a function at normalizeEmailCase (/home/app/node_modules/loopback/common/models/user.js:605:55

This is the offending code:

    // Access token to normalize email credentials
    UserModel.observe('access', function normalizeEmailCase(ctx, next) {
      if (!ctx.Model.settings.caseSensitiveEmail && ctx.query.where && ctx.query.where.email) {
        ctx.query.where.email = ctx.query.where.email.toLowerCase();
      }
      next();
    });

This is assuming that email is a string when it may well not be, as in the example above.

0candy commented 8 years ago

The where clause is expecting a string or regex, could you try? { "or": [ {"email": "example1@example.com"}, {"email": "example2@example.com"} ] }

See docs: https://docs.strongloop.com/display/public/LB/Where+filter

mrfelton commented 8 years ago

@0candy Is this not a valid where query? I don't think I should have to use the format you have suggested.

where: {
    email: {
        inq:[ 'example1@example.com', 'example2@example.com' ]
    }
},
mrfelton commented 8 years ago

See https://docs.strongloop.com/display/public/LB/Where+filter#Wherefilter-inq

mrfelton commented 8 years ago

Note that query I've highlighted is not problematic if caseSensitiveEmail is not disabled

0candy commented 8 years ago

You are right, that is a bug. Thanks for pointing it out.

stale[bot] commented 7 years ago

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.