Getting Additional Data During Login

3 posts, 1 answers
  1. Kelly
    Kelly avatar
    73 posts
    Member since:
    Apr 2011

    Posted 30 May 2014 Link to this post

    Hello,

    My goal is to return some data that is not stored in the Users content type when each user logs in.  Basically, I want to avoid a second round trip to retrieve settings information after a successful login, by just injecting the settings in the Cloud Code.

    I tried adding fields to the response.additionalData in the afterRead event for my Users type.  But the info returned by everlive.Users.currentUser doesn't reflect the additionalData fields.

    Is there a way to return additional data in the currentUser call?

    Thank you,

    Kelly
  2. Answer
    Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 30 May 2014 Link to this post

    Hi Kelly,

    The el.Users.CurrentUser() function makes a getById call to the REST API. In the cloud code of the Users content type you can set up the following code for incoming requests by Id:

    Everlive.Events.afterRead(function(request, response, context, done) {
      var isCheckSatisfied; // some additional check
      
      if(request.itemId && isCheckSatisfied) {
        response.result.userInfo = { "isReturningCustomer" : true };
      }
     
      done();
    });

    which will add the additional data to the result for the current user.

    Using response.additionalData will work in all other content types.

    Please, let us know if this works for you.

    Regards,
    Anton Dobrev
    Telerik
     
    Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
     
  3. Kelly
    Kelly avatar
    73 posts
    Member since:
    Apr 2011

    Posted 30 May 2014 in reply to Anton Dobrev Link to this post

    Thank you, Anton.  That worked perfectly.
Back to Top