5

Right now, I am using a MsalProvider to authenticate a user based on the Microsoft account they are signed in with. And three things happen when a component mounts:

  1. The app obtains a token from MSAL using @azure/msal-react
  2. Use this token to call an internal API
  3. The data from this API is then rendered on the user's browser

Since I'm dependant on a users Microsoft account credentials, everything has to render on the client side? Or is there a way I can make use of getServerSideProps(...) here so that it can SSR?

aayani
  • 333
  • 9
  • 19
  • 1
    One such approach is to store a cookie with user information and then use this cookie to identify a user during getServerSideProps stage. Then it's possible to make the API call on their behalf. But I'm not sure if that's worth it, since it won't work on first load (or until the cookie is available) and also the MSAL token has a limited TTL. – aayani Oct 17 '22 at 14:30
  • Trying to do the same for my react app. from when i can tell, you need to use msal node instead of msal browser to generate the token serverside. I am still trying to figure out how the login and msal node can flow smoothly, but its a good start. https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib/msal-node – CodingSlayer Oct 30 '22 at 07:19

0 Answers0