none
Azure Easy table add the email to the context.user

    Question

  • Hi:

    We need to store the email in the context to be able to reuse it during all of our interactions with the Easy Tables to avoid invoking the getIdentity() function in each table.

    I found this javascript:  

    var authCache = {};
     
    function authMiddleware(request, response, next) {
      
      if (typeof request.azureMobile.user !== 'undefined') {
     
        if (typeof authCache[request.azureMobile.user.id] !== 'undefined') {
          
          request.azureMobile.user.emailaddress = authCache[request.azureMobile.user.id];
          next();
        }
        request.azureMobile.user.getIdentity().then(function (userInfo) {
          if (typeof userInfo.microsoftaccount.claims.emailaddress !== 'undefined') {
            authCache[request.azureMobile.user.id] = userInfo.microsoftaccount.claims.emailaddress;
            request.azureMobile.user.emailaddress = authCache[request.azureMobile.user.id];
          }
          next();
        });
      } else {
        next();
      }
      
    }
     
    module.exports = authMiddleware;

    The problem is that once I enabled this in the App.js the Xamarin Forms application that consume this Azure backend starts to fail.  For example, the table read returns no records, but the next time return a record.  Is totally inconsistent.

    Do you have any idea of what could be causing this issue or what strategy can I use to debug this.

    Thanks

    David

    Saturday, September 17, 2016 12:45 AM

Answers

All replies