title: Loopback unauthorized request when trying to login
body: <p>I have created a custom user model that inherits form the built-in User model. Then I added a boot script that creates a default user. </p>
  
  <pre><code> User.create([{
     username: 'admin',
     email: 'email@email.com',
     password: 'admin'
  }], on_usersCreated);
  </code></pre>
  
  <p>This creates a document in the monogdb database,. However when I try to login, it send a 401 unauthorized request.</p>
  
  <p>I tried to find the root of the problem, and it seems that loopback cannot fins such user in the database. More specifically, in node_modules/loopback/common/models/user there is this:</p>
  
  <pre><code>self.findOne({where: query}, function(err, user) {
    var defaultError = new Error('login failed');
    defaultError.statusCode = 401;
    ....
  </code></pre>
  
  <p>where </p>
  
  <pre><code>query = { email: "email@email.com" }
  </code></pre>
  
  <p>But the problem is that it cannot find a user with that email in the database although it does exist.</p>
  
  <p>This is the user.json file</p>
  
  <pre><code>{
    "name": "user",
    "base": "User",
    "idInjection": true,
    "properties": {},
    "validations": [],
    "relations": {},
    "acls": [
     {
        "accessType": "*",
        "principalType": "ROLE",
        "principalId": "$everyone",
        "permission": "DENY"
     },
     {
        "accessType": "*",
        "principalType": "ROLE",
        "principalId": "admin",
        "permission": "ALLOW"
     }
   ],
   "methods": []
  }
  </code></pre>