Skip to content

Add a hook or flag to distinguish between authenticated users and users assigned to the current application in msal-react #7774

Open
@akshayquest

Description

@akshayquest

Core Library

MSAL.js (@azure/msal-browser)

Wrapper Library

MSAL React (@azure/msal-react)

Public or Confidential Client?

Public

Description

Currently, the useIsAuthenticated hook in msal-react returns true if there is a cached account, even if the user is not actually assigned to the Azure AD B2C application. This leads to scenarios where users who are authenticated but not assigned to the app are redirected to protected routes, resulting in errors like AAD_Custom_UserNotAssignedToApplication.

It would be very helpful to have a hook or flag (e.g., useIsAssignedToApp) that only returns true if the authenticated user is actually assigned to the current application. This would allow developers to provide a better user experience and avoid unnecessary errors or redirect loops for unassigned users.

Use case:
When a user visits the root route (/), we want to show the landing page for users who are not assigned to the app, even if they are authenticated in Azure AD B2C, and only redirect assigned users to the home page.

Thank you for considering this feature!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: Author FeedbackAwaiting response from issue authorfeature-unconfirmedmsal-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