Events

June 16, 2026 ยท View on GitHub

Msal Browser (@azure/msal-browser) provides event APIs that are available to users of our core library and wrapper libraries. These events are related to auth and what MSAL is doing, and can be used in applications to update UI, show error messages, and so on.

:warning: Do not use events for telemetry. Events are intended for reacting to auth state changes in your application (e.g. updating UI or showing error messages). They are not a telemetry mechanism: the set of events, their timing, and their payloads are not guaranteed to be stable across versions, and relying on them to collect metrics or measure performance is not supported. For telemetry and performance monitoring, see Performance and Telemetry config options.

What events look like

export type EventMessage = {
    eventType: EventType;
    interactionType: InteractionType | null;
    payload: EventPayload;
    error: EventError;
    timestamp: number;
};

You can consult the EventPayload and EventError type docs to understand how they are defined in MSAL.

How events are emitted in MSAL Browser

Msal Browser has a protected function emitEvent, and emits events in major APIs. For the list of currently emitted events, see the table below.

Here is an example of how MSAL Browser emits an event with a payload, or with an error:

this.emitEvent(EventType.ACQUIRE_TOKEN_SUCCESS, InteractionType.Redirect, result);

this.emitEvent(EventType.ACQUIRE_TOKEN_FAILURE, InteractionType.Redirect, null, e);

How to use the event API

Msal-browser exports the addEventCallback function which takes in a callback function and can be used to process emitted events.

Here is an example of how you could consume the emitted events in your application:

const callbackId = msalInstance.addEventCallback((message: EventMessage) => {
    // Update UI or interact with EventMessage here
    if (message.eventType === EventType.LOGIN_SUCCESS) {
        console.log(message.payload);
    }
});

Adding an event callback will return an id. This id can be used to remove the callback if necessary, using the removeEventCallback function exported by msal-browser:

msalInstance.removeEventCallback(callbackId);

Handling errors

Due to the way EventError is defined, handling errors emitted with an event may require validating that the error is of the correct type before accessing specific properties on the emitted error. The error can be cast to AuthError or checked that it is an instance of AuthError.

Here is an example of consuming an emitted event and casting the error:

const callbackId = msalInstance.addEventCallback((message: EventMessage) => {
    // Update UI or interact with EventMessage here
    if (message.eventType === EventType.ACQUIRE_TOKEN_FAILURE) {
        if (message.error instanceof AuthError) {
            // Do something with the error
        }
    }
});

Getting interaction status from events

You can get the current interaction status from events by using the getInteractionStatusFromEvent API:

Here is an example of displaying a message when there are no interactions in progress:

const callbackId = msalInstance.addEventCallback((message: EventMessage) => {
    const status = EventMessageUtils.getInteractionStatusFromEvent(message);

    // Update UI or interact with EventMessage here
    if (status === InteractionStatus.None) {
        console.log(message.payload);
    }
});

Syncing logged in state across tabs and windows

If you would like to update your UI when a user logs in or out of your app or changes the active account in a different tab or window you can subscribe to the LOGIN_SUCCESS, LOGOUT_SUCCESS, and ACTIVE_ACCOUNT_CHANGED events.

  • For account additions and removals, the payload will be the AccountInfo object that was added or removed.
  • For active account updates, there will be no payload
msalInstance.addEventCallback((message: EventMessage) => {
    if (message.eventType === EventType.LOGIN_SUCCESS) {
        // Update UI with new account
    } else if (message.eventType === EventType.LOGOUT_SUCCESS) {
        // Update UI with account logged out
    } else if (message.eventType === EventType.ACTIVE_ACCOUNT_CHANGED) {
        const accountInfo = msalInstance.getActiveAccount();
        // Update UI with new active account info
    }
});

Table of events

These are the events currently emitted by msal-browser.

Event TypeDescriptionInteraction TypePayloadError
LOGIN_STARTLoginPopup or loginRedirect is calledPopup or RedirectPopupRequest or RedirectRequest
LOGIN_SUCCESSSuccessfully logged inPopup or RedirectAccountInfo
LOGIN_FAILUREError when logging inPopup or RedirectAuthError or Error
ACQUIRE_TOKEN_STARTAcquireTokenPopup or acquireTokenRedirect or acquireTokenSilent is calledPopup or Redirect or SilentPopupRequest or RedirectRequest or SilentRequest
ACQUIRE_TOKEN_SUCCESSSuccessfully acquired token from cache or networkPopup or Redirect or SilentAuthenticationResult
ACQUIRE_TOKEN_FAILUREError when acquiring tokenPopup or Redirect or SilentAuthError or Error
HANDLE_REDIRECT_STARTHandleRedirectPromise calledRedirect
HANDLE_REDIRECT_ENDHandleRedirectPromise finishedRedirect
LOGOUT_STARTLogout calledRedirect or PopupEndSessionRequest or EndSessionPopupRequest
LOGOUT_ENDLogout finishedRedirect or Popup
LOGOUT_SUCCESSLogout successRedirect or PopupEndSessionRequest or EndSessionPopupRequest
LOGOUT_FAILURELogout failedRedirect or PopupAuthError or Error
ACTIVE_ACCOUNT_CHANGEDActive account filters where changed in a different tab or windowN/AN/ANA
INITIALIZE_STARTInitialize function calledN/AN/AN/A
INITIALIZE_ENDInitialize function completedN/AN/AN/A