Merging Users in Kinvey

我与影子孤独终老i 提交于 2019-12-12 17:22:58

问题


Situation:

  1. User A registers an account in our application and logs in.
  2. For what ever reason logs out.
  3. Logs in to the application again using Facebook social sign on with an account that has the same email associated with it as the original registration had.
  4. A second account is created for this sign on and 2 accounts exist in the system.

How can I merge these accounts into a single account during the social sign on (by querying for the existence of that email) automatically or with User Collection Business Hooks (if with business hooks, can you please provide an example of how I would do this as documentation online is unclear for this specific purpose).

Notes:

  • Kinvey backend
  • Phonegap with facebook plugin
  • Jquery mobile
  • Wish to merge accounts or find existing account and add social identity to it during sign on
  • Assume I cannot delete users
  • Preferably achieve this step with a PreSave Kinvey Business Logic Hook

Cheers,


回答1:


I managed to create my own custom end point to basically achieve user merging.

If a user exists with a kinvey account, then tries to log in using facebook with an email address matching a kinvey user, I used the following end point code to add a social identity to the existing user before attempting to log in using that user (This function only worked because we maintain a guest login for users not logged in to the system).

Hope this helps some one.

function onRequest(request, response, modules) {
  var users = modules.collectionAccess.collection('user');
  var social = request.body.social;
  users.findAndModify({"username":request.body.email},{$set:{"_socialIdentity":social}},
  function(err,result){
    if(err){
      response.error(err);
      response.complete();
    }else{
     if(!result._id){
       response.body = {message:"No User Found Matching This Email"};
       response.complete();
     }else{
       response.body = {message:"User Was Hopefully Updated"};
       response.complete();
     }
    }
  });
}


来源:https://stackoverflow.com/questions/34946105/merging-users-in-kinvey

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!