Skip to content

useIsAuthenticated() is not reactive #8032

@vponnurudb

Description

@vponnurudb

Core Library

MSAL.js (@azure/msal-browser)

Core Library Version

3.1.0

Wrapper Library

MSAL React (@azure/msal-react)

Wrapper Library Version

3.0.19

Public or Confidential Client?

Public

Description

useIsAuthenticated() is not reactive. I am using the state variable as a dependency in useEffect. But after authentication completes, the useEffect is not triggered.

const isConnected = useIsAuthenticated()
const [xyz, setXyz] = useState()

useEffect(()=> {

// do something to xyz

}, [isConnected]

I need to update my app's local xyz state based on isConnected's change in state. But the useEffect is not triggered after successful authentication. Is this the expected behavior?

Error Message

No response

MSAL Logs

No response

Network Trace (Preferrably Fiddler)

  • Sent
  • Pending

MSAL Configuration

{auth: {
    clientId: "xxxxx",
    authority: "https://login.microsoftonline.com/xxxxx",
    redirectUri: "http://localhost:3000/"
  },
}
};

Relevant Code Snippets

const isConnected = useIsAuthenticated()
const [xyz, setXyz] = useState()

useEffect(()=> {

console.log("useEffect called.")
// do something to xyz

}, [isConnected]

Reproduction Steps

See code snippet

Expected Behavior

useEffect() is called and state is updated. But useEffect() is not called after state changes.
A reload of the component shows the correct state. So the state is updating successfully. Its just not reactive.

Identity Provider

Entra ID (formerly Azure AD) / MSA

Browsers Affected (Select all that apply)

Chrome

Regression

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: Attention 👋Awaiting response from the MSAL.js teambug-unconfirmedA reported bug that needs to be investigated and confirmedmsal-browserRelated to msal-browser packagemsal-reactRelated to @azure/msal-reactpublic-clientIssues regarding PublicClientApplicationsquestionCustomer is asking for a clarification, use case or information.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions