This is a migrated thread and some comments may be shown as answers.

Getting Additional Data During Login

2 Answers 90 Views
Cloud Code
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kelly
Top achievements
Rank 1
Kelly asked on 30 May 2014, 02:34 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Anton Dobrev
Telerik team
answered on 30 May 2014, 04:35 PM
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.
 
0
Kelly
Top achievements
Rank 1
answered on 30 May 2014, 04:48 PM
Thank you, Anton.  That worked perfectly.
Tags
Cloud Code
Asked by
Kelly
Top achievements
Rank 1
Answers by
Anton Dobrev
Telerik team
Kelly
Top achievements
Rank 1
Share this question
or