Skip to content

useIsAuthenticated hook returning true when token is expired #5456

Description

Core Library

MSAL.js v2 (@azure/msal-browser)

Core Library Version

2.32.0

Wrapper Library

MSAL React (@azure/msal-react)

Wrapper Library Version

1.5.0

Public or Confidential Client?

Public

Description

I'm using the useIsAuthenticated() hook to render specific components when a user is signed in with a valid session. When the token expires, useIsAuthenticated() returns true.

Error Message

InteractionRequiredAuthError: interaction_required: AADSTS70044: The session has expired or is invalid due to sign-in frequency checks by conditional access.
Trace ID: c6c8ef47-fefa-4c22-a062-0c711089dc00
Correlation ID: b72a73fe-3359-44ca-b770-8eaab110d757

Msal Logs

No response

MSAL Configuration

{
  auth: {
    clientId: '',
    authority: '',
    redirectUri: window.location.origin
  },
  cache: {
    cacheLocation: 'localStorage',
    storeAuthStateInCookie: false 
  }
}

Relevant Code Snippets

import { useIsAuthenticated } from '@azure/msal-react'
const IsAuthenticated = useIsAuthenticated()

export default function MyComponent () {
  return (
     IsAuthenticated === true
       ? Valid Session
       : Invalid Session
  )
}

Reproduction Steps

  1. Wait for the token to expire
  2. Log the return value of useIsAuthenticated()

Expected Behavior

useIsAuthenticated() should be returning false when a session is invalid.

Identity Provider

Azure AD / MSA

Browsers Affected (Select all that apply)

Chrome

Regression

No response

Source

External (Customer)

Metadata

Metadata

Labels

bug-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