Copying Normalized Profile To DB In SPA/Mobile App

Let’s say I’m writing a mobile app or single page app with a REST API backend. In the database that the REST API connects to, there is a user table that stores the Normalized Profile for each user, and updates on login. This table wouldn’t have sensitive info like passwords, just stuff like name and profile picture. What would be the best way to copy normalized profiles and store them in the DB, so that they can be related to other tables or allow users of the app to view another user’s profile (spefically in the context of something like a MEAN stack app where the client and server are seperated)?

You have the ability to get a hold of the profile information via a rule, and choose to save it in a backend of your choice. I don’t know if saving/updating profile information during login is the right place for your application, but it is certainly a possibility.

Here is an example rule that will allow you to update the user profile entry in FireBase

function (user, context, callback) {
  var baseURL = configuration.FIREBASE_URL;
  var secret = configuration.FIREBASE_SECRET;
  var fb_id = new Buffer(user.user_id).toString('base64');

  var fbIdentity = {
    "identity": {
      "user_id": user.user_id,
      "email": user.email,
      "name": user.name,
      "nickname": user.nickname,
      "picture": user.picture
    }
  };

  var putURL = baseURL + "/users/" + fb_id + ".json?auth=" + secret;
  request.put({
    "url": putURL,
    "json": fbIdentity
  },
  function(err, response, body) {
    if (err) return callback(err);
    return callback(null, user, context);
  });
}

You should also ensure that this operation is quick or asynch. For instance, you could put the profile information on a queue and a job can update the profile, asynchronous to the login process.

Auth0 also has the concept of normalized user profiles that you may find extremely useful when working with multiple identity providers or protocols, this should simplify your code by isolating you from the various identity providers, you may find this link useful, Normalized User Profiles

Certainly there are many other relevant concepts such as enriching profiles, or converging multiple social identities and building a profile out of all of them etc.

Sahil

Thank you for your reply. The app is somewhat like a social media profile, and I am saving the user profiles to allow me to create relationships in the database between the user and other application data, and to display user profiles to other users. If you believe there is a better way to do this, please let me know.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.