Paul Lawrence
Paul Lawrence

Reputation: 327

When using @azure/Msal-browser, I get this error message on ClientAuthError: state_not_found: State not found

I'm developing an using @azure/msal-browser on http://localhost using create-react-app, when trying to login via msal.loginRedirect() the browser retuns to the site, and correct page however the user is not logged in and the following error is in the console (from the handleRedirectPromise method) ClientAuthError: state_not_found: State not found: Cached State

A state parameter is passed into the login url (https://login.microsoft.com...state=base64string...) but nothing is in the Local/Session/Cookie storage.

The Azure app config is fine (having being used before), something is not wokring/configured with the msal library, any ideas?

Upvotes: 5

Views: 10968

Answers (2)

Mikita Melnikau
Mikita Melnikau

Reputation: 1775

I got this error in NextJS app when wrap the MSAL Provider with top level logger context. The issue was in useEffect usage inside logger context - it was making an incorrect rendering order, and because of this the page was crushing with errors state_not_found or no_cached_authority_error - was depends of my MSAL module codebase. Hope it may help for some one.

Upvotes: 0

SubliemeSiem
SubliemeSiem

Reputation: 1159

This error can be caused if the handleRedirectPromise is called twice. msal-react should call this function for you, so there is no need to do this call yourself. See this github issue for more information: msal-browser redirect not working correctly.

Upvotes: 4

Related Questions