Search code examples
reactjsmicrosoft-teamsspfxmicrosoft-graph-toolkit

Microsoft Graph Toolkit: get logged in user


I am using the Login component <Login /> of the Microsoft Graph Toolkit (React flavor). How can I retrieve the display name and User Principal Name of the logged in user?

I see that the component has a loginCompleted prop, but the user is not passed as argument.


Solution

  • After getting advice from Microsoft, and reviewing a sample, here is the code I came up with:

        <Login
          loginCompleted={(e) => {
            Providers.globalProvider.graph.client.api('me').get()
              .then(gotMe => DoStuff(gotMe));
          }}
          logoutCompleted={(e) => { }}
        />