Closed pulkitsinghal closed 9 years ago
I went ahead and attempted to sanity test this in a boot script:
// login w/ merchant1
UserModel.login(
{realm: 'portal', username: retailUser.username, password: 'xxx'},
function(err, accessToken) {
if (err) return debug('%j', err);
debug(accessToken);
debug('logged in w/ ' + retailUser.username + ' and token ' + accessToken.id);
});
And the result was:
boot:create-model-instances {
ttl: 1209600,
userId: undefined,
created: Wed Apr 01 2015 11:05:49 GMT-0500 (CDT),
id: '1GcFtx1APKWBgLRejaYbv7dxW1U1vl2bCIGTPiNw7lGiupkbpzWLEzKLRagvWbIK'
} +342ms
boot:create-model-instances logged in w/ merchant1@shoppinpal.com and token 1GcFtx1APKWBgLRejaYbv7dxW1U1vl2bCIGTPiNw7lGiupkbpzWLEzKLRagvWbIK +0ms
So userId isn't being set is obvious ... I wonder, where in the core loopback code should I dig for the login() method?
Do you use the ES connector to back the user model?
Yes, UserModel extends the built in user model
@raymondfeng So when the UserModel
is backed by memory connector, there's no problem but when it is backed by ES, this issue crops up.
@raymondfeng - can you point me to a test that I can copy/paste and use to explore what might be wrong with my connector?
@sumitha No, there is no example for that specific situation. I suggest digging through the source code of other connectors, most likely https://github.com/strongloop/loopback-connector-mongodb in this case since ES is a document-oriented database.
Digging through the User.login
method may help also.
can you point me to a test that I can copy/paste and use to explore what might be wrong with my connector?
https://github.com/strongloop/loopback/blob/master/test/user.test.js
@superkhau - in user.test.js
I don't see app
variable getting initialized anywhere, does this test have a parent that calls or requires it?
https://github.com/strongloop/loopback/blob/master/test/user.test.js#L34
in user.test.js I don't see app variable getting initialized anywhere, does this test have a parent that calls or requires it?
I would like to get rid of that support file because it makes the test difficult to understand.
In the all() method it makes sense to return the id
with the content! Its a given on other datasources but for a datasource like elasticsearch, we need to make sure and map "_id" into the content, just in case its an auto-generated one.
Also need to make sure that the model property marked as id: true
(if it is configured) is the one that gets the value.
Simple tests have been added to prevent regression.
When I use the
memory
connector, the accessToken looks like:But when I use the
elasticsearch
connector, it looks like:Notice how the
userId
is missing forreq.accessToken
when elasticsearch connector is involved?