Search code examples
reactjsazure-ad-msal

MSAL Acquire token silently or token stored in local storage?


I am using Msal library for authentication purpose in my react app. I am confused if I call acquireTokenSiliently method before each api call to fetch the access token or shall I store it to local storage first time and use that token in subsequent calls ? What's the best practice while using the MSAL library in react ?


Solution

  • You should first call the acquireTokenSilently method before api call. Then store the token inside the localStorage. Then when you call the API you should then get the token from the localStorage and send the token with the request.

    Read more here.