/**
 * Adds the ID of the user object stored on our database
 * to the token returned from Auth0
 */
function (user, context, callback) {
  var namespace = 'https://techbikers.com/';
  context.idToken[namespace + 'user_id'] = user.app_metadata.id;
  callback(null, user, context);
}

/**
 * Adds the ID of the user object stored on our database
 * to the token returned from Auth0
 */
function (user, context, callback) {
  var namespace = 'https://techbikers.com/';

  // If the user has app_metadata then inject the ID into the token
  if (user.app_metadata) {
    context.idToken[namespace + 'user_id'] = user.app_metadata.id;
  }

  callback(null, user, context);
}

Check to make sure app_metadata exists
Check to make sure app_metadata exists

There shouldn’t be cases where app_metadata doesn’t exist but if it doesn’t then it will cause an error that prevents the user from being logged in.

Signed-off-by: Michael Willmott <4063ad43ea4e0ae77bf35022808393a246bdfa61@gmail.com>
