Skip to content

How to get additional Fields in User Login Method #3641

Closed

Description

@rahulrsingh09

Presently i get the Four default fields in a Loopback login method

{
  "id": "LoXj3QXFepPP7qGiHaWPd7GCjAdenxZVvJwaIM652pSG1SJvqB9fHTU0UdMEiaCL",
  "ttl": 1440,
  "created": "2017-10-05T17:48:42.849Z",
  "userId": 1908
}

Now i want to get another field of the user Model acc_id but how to get that this is a overridden user model

Activity

  1. landervs commented on Oct 6, 2017

    @landervs

    You can extend the base User model. Read about it here: https://loopback.io/doc/en/lb2/Extending-built-in-models.html

    I have stored the original User model in a memory database because this one is not used, and the extended one in my MYSQL database, this to avoid duplicates.

  2. rahulrsingh09 commented on Oct 6, 2017

    @rahulrsingh09
    Author

    @landervs I have extended the User model currently and i have the following Relation but i cannot include the Data of a related module {"include":<model>}
    always throws error says include.toLowerCase() is not a function in loopbacks module

  3. landervs commented on Oct 6, 2017

    @landervs

    /UrlToEndPoint?filter[include]=model works fine for me.

    See https://loopback.io/doc/en/lb3/Include-filter.html

  4. rahulrsingh09 commented on Oct 6, 2017

    @rahulrsingh09
    Author

    @landervs I want to Include it as a part of a remote method code

    return user.login(credentials,{include: 'account'}, function(loginErr, loginToken) {
    ~```
    
  5. phortonssf commented on Oct 10, 2017

    @phortonssf

    I am trying to do the same retrieve the related data to the user on login seems far more logical then another http call.

  6. bajtos commented on Oct 13, 2017

    @bajtos
    Member

    Please note that User.login method is returning the access token created for the new session, not the user instance. As @landervs mentioned in their comment above, you can add ?filter[include]=user to your login URL in order to include full data of the logged-in user in the response. See #163 which implemented this feature, and the unit-test showing how to use it:

    loopback/test/user.test.js

    Lines 833 to 849 in f30159c

    it('Returns current user when `include` is `USER`', function(done) {
    request(app)
    .post('/test-users/login?include=USER')
    .send(validCredentials)
    .expect(200)
    .expect('Content-Type', /json/)
    .end(function(err, res) {
    if (err) return done(err);
    var token = res.body;
    expect(token.user, 'body.user').to.not.equal(undefined);
    expect(token.user, 'body.user')
    .to.have.property('email', validCredentials.email);
    done();
    });
    });

    Right now, it's not possible to fetch any additional relations besides the user, see #1477 which is tracking that feature request. I am closing this as a duplicate of #1477.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions