Search code examples
azure-ad-b2cmsal.jsmsal-react

Callback Event after successful login msal-react


I'm using <MsalAuthenticationTemplate interactionType={InteractionType.Redirect}> to redirect the user to the login page. How can I perform a function after successful login? Is there a callback event I can hook in?


Solution

  • There are quite a few events available.

    Event Type Description Interaction Type Payload Error
    LOGIN_START LoginPopup or loginRedirect is called Popup or Redirect PopupRequest or RedirectRequest
    LOGIN_SUCCESS Successfully logged in Popup or Redirect AuthenticationResult
    LOGIN_FAILURE Error when logging in Popup or Redirect AuthError or Error
    ACQUIRE_TOKEN_START AcquireTokenPopup or acquireTokenRedirect or acquireTokenSilent is called Popup or Redirect or Silent PopupRequest or RedirectRequest or SilentRequest
    ACQUIRE_TOKEN_SUCCESS Successfully acquired token from cache or network Popup or Redirect or Silent AuthenticationResult
    ACQUIRE_TOKEN_FAILURE Error when acquiring token Popup or Redirect or Silent AuthError or Error
    ACQUIRE_TOKEN_NETWORK_START Starting acquiring token from network Silent
    SSO_SILENT_START SsoSilent API called Silent SsoSilentRequest
    SSO_SILENT_SUCCESS SsoSilent succeeded Silent AuthenticationResult
    SSO_SILENT_FAILURE SsoSilent failed Silent AuthError or Error
    HANDLE_REDIRECT_START HandleRedirectPromise called Redirect
    HANDLE_REDIRECT_END HandleRedirectPromise finished Redirect
    LOGOUT_START Logout called Redirect or Popup EndSessionRequest or EndSessionPopupRequest
    LOGOUT_END Logout finished Redirect or Popup
    LOGOUT_SUCCESS Logout success Redirect or Popup EndSessionRequest or EndSessionPopupRequest
    LOGOUT_FAILURE Logout failed Redirect or Popup AuthError or Error

    Source: MSAL Browser documentation - Events

    Looks like you're looking for the LOGIN_SUCCESS event.