question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NextJS custom router: iOS Safari redirect loop when ITP enabled

See original GitHub issue

Core Library

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

Core Library Version

2.20.0

Wrapper Library

MSAL React (@azure/msal-react)

Wrapper Library Version

1.1.2

Description

Any attempt to log in on any iOS browser with Intelligent Tracking Protection starts a redirect loop. Works fine on desktop Safari & other desktop browsers as well as Android, and if I turn ITP off it works on mobile Safari as well.

Error Message

No error

Msal Logs

[Log] [Wed, 08 Dec 2021 18:14:43 GMT] : [4a3ab3d5-935f-4ebc-963e-f06605b598bb] : msal.js.browser@2.20.0 : Verbose - RedirectHandler.initiateAuthRequest: Navigating window to navigate url
[Log] [Wed, 08 Dec 2021 18:14:43 GMT] : @azure/msal-browser@2.20.0 : Verbose - getAllAccounts called
[Log] [Wed, 08 Dec 2021 18:14:43 GMT] : @azure/msal-browser@2.20.0 : Verbose - getAllAccounts called
[Warning] Invalid HMR message: {"action":"sync","hash":"4a5e27464e5e8db3","warnings":[],"errors":[]}
Error: No router instance found.
You should only use "next/router" on the client side of your app.

[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-browser@2.20.0 : Verbose - Event callback registered with id: c90edf90-4821-4265-96f1-cc767d8a980c
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-react@1.1.2 : Verbose - MsalProvider - Registered event callback with id: c90edf90-4821-4265-96f1-cc767d8a980c
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-browser@2.20.0 : Verbose - Event callback registered with id: 3961faf2-96c8-4b41-ba61-b2e5fc02f8d4
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-react@1.1.2 : Verbose - MsalProvider - Registered event callback with id: 3961faf2-96c8-4b41-ba61-b2e5fc02f8d4
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-browser@2.20.0 : Verbose - handleRedirectPromise called
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-browser@2.20.0 : Verbose - getAllAccounts called
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-browser@2.20.0 : Info - Emitting event: msal:handleRedirectStart
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-browser@2.20.0 : Verbose - Emitting event to callback c90edf90-4821-4265-96f1-cc767d8a980c: msal:handleRedirectStart
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-browser@2.20.0 : Verbose - Emitting event to callback 3961faf2-96c8-4b41-ba61-b2e5fc02f8d4: msal:handleRedirectStart
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-react@1.1.2 : Info - MsalProvider - msal:handleRedirectStart results in setting inProgress from startup to handleRedirect
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-browser@2.20.0 : Verbose - handleRedirectPromise has been called for the first time, storing the promise
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : [4a3ab3d5-935f-4ebc-963e-f06605b598bb] : msal.js.browser@2.20.0 : Verbose - initializeServerTelemetryManager called
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : [4a3ab3d5-935f-4ebc-963e-f06605b598bb] : msal.js.browser@2.20.0 : Verbose - getRedirectResponseHash called
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : [4a3ab3d5-935f-4ebc-963e-f06605b598bb] : msal.js.browser@2.20.0 : Verbose - Hash contains known properties, returning response hash
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : [4a3ab3d5-935f-4ebc-963e-f06605b598bb] : msal.js.browser@2.20.0 : Verbose - validateAndExtractStateFromHash called
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : [4a3ab3d5-935f-4ebc-963e-f06605b598bb] : msal.js.browser@2.20.0 : Verbose - Returning state from hash
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : [4a3ab3d5-935f-4ebc-963e-f06605b598bb] : msal.js.browser@2.20.0 : Verbose - State extracted from hash
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : [4a3ab3d5-935f-4ebc-963e-f06605b598bb] : msal.js.browser@2.20.0 : Verbose - Navigating to loginRequestUrl: http://localhost:8222/brand/contracts
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-browser@2.20.0 : Verbose - getAllAccounts called
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-browser@2.20.0 : Verbose - Adding account storage listener.
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-browser@2.20.0 : Verbose - Event callback registered with id: b441eb38-965b-44b4-a36e-e437e1c21cdf
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-browser@2.20.0 : Info - Emitting event: msal:handleRedirectEnd
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-browser@2.20.0 : Verbose - Emitting event to callback c90edf90-4821-4265-96f1-cc767d8a980c: msal:handleRedirectEnd
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-browser@2.20.0 : Verbose - getAllAccounts called
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-react@1.1.2 : Info - MsalProvider - no account changes
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-browser@2.20.0 : Verbose - Emitting event to callback 3961faf2-96c8-4b41-ba61-b2e5fc02f8d4: msal:handleRedirectEnd
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-react@1.1.2 : Info - MsalProvider - msal:handleRedirectEnd results in setting inProgress from handleRedirect to none
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-browser@2.20.0 : Verbose - Emitting event to callback b441eb38-965b-44b4-a36e-e437e1c21cdf: msal:handleRedirectEnd
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-browser@2.20.0 : Verbose - getAllAccounts called
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-browser@2.20.0 : Verbose - getAllAccounts called
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-browser@2.20.0 : Verbose - Event callback registered with id: 05e96fa7-8d01-4bea-a405-c3542688d4d6
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-react@1.1.2 : Verbose - useMsalAuthentication - Registered event callback with id: 05e96fa7-8d01-4bea-a405-c3542688d4d6
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-react@1.1.2 : Info - useMsalAuthentication - No user is authenticated, attempting to login
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-react@1.1.2 : Verbose - useMsalAuthentication - Calling ssoSilent
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-browser@2.20.0 : Verbose - preflightBrowserEnvironmentCheck started
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-browser@2.20.0 : Verbose - ssoSilent called
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-browser@2.20.0 : Info - Emitting event: msal:ssoSilentStart
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-browser@2.20.0 : Verbose - Emitting event to callback c90edf90-4821-4265-96f1-cc767d8a980c: msal:ssoSilentStart
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-browser@2.20.0 : Verbose - Emitting event to callback 3961faf2-96c8-4b41-ba61-b2e5fc02f8d4: msal:ssoSilentStart
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-react@1.1.2 : Info - MsalProvider - msal:ssoSilentStart results in setting inProgress from none to ssoSilent
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-browser@2.20.0 : Verbose - Emitting event to callback b441eb38-965b-44b4-a36e-e437e1c21cdf: msal:ssoSilentStart
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-browser@2.20.0 : Verbose - Emitting event to callback 05e96fa7-8d01-4bea-a405-c3542688d4d6: msal:ssoSilentStart
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : [55e92e0d-a9d6-4939-b4d9-10820922389a] : msal.js.browser@2.20.0 : Verbose - acquireTokenByIframe called
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : [55e92e0d-a9d6-4939-b4d9-10820922389a] : msal.js.browser@2.20.0 : Warning - No user hint provided. The authorization server may need more information to complete this request.
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : [55e92e0d-a9d6-4939-b4d9-10820922389a] : msal.js.browser@2.20.0 : Verbose - initializeAuthorizationRequest called
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : [55e92e0d-a9d6-4939-b4d9-10820922389a] : msal.js.browser@2.20.0 : Verbose - getRedirectUri called
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : [55e92e0d-a9d6-4939-b4d9-10820922389a] : msal.js.browser@2.20.0 : Verbose - Initializing BaseAuthRequest
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : [55e92e0d-a9d6-4939-b4d9-10820922389a] : msal.js.browser@2.20.0 : Verbose - Authentication Scheme wasn't explicitly set in request, defaulting to "Bearer" request
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : [55e92e0d-a9d6-4939-b4d9-10820922389a] : msal.js.browser@2.20.0 : Verbose - initializeServerTelemetryManager called
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : [55e92e0d-a9d6-4939-b4d9-10820922389a] : msal.js.browser@2.20.0 : Verbose - initializeAuthorizationRequest called
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-browser@2.20.0 : Verbose - getAllAccounts called
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : [55e92e0d-a9d6-4939-b4d9-10820922389a] : msal.js.browser@2.20.0 : Verbose - getClientConfiguration called
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : [55e92e0d-a9d6-4939-b4d9-10820922389a] : msal.js.browser@2.20.0 : Verbose - getDiscoveredAuthority called
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : [55e92e0d-a9d6-4939-b4d9-10820922389a] : msal.js.browser@2.20.0 : Verbose - Creating discovered authority with request authority
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-browser@2.20.0 : Verbose - getAllAccounts called
[Log] [Wed, 08 Dec 2021 18:14:49 GMT] : @azure/msal-browser@2.20.0 : Verbose - getAllAccounts called
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : [55e92e0d-a9d6-4939-b4d9-10820922389a] : msal.js.browser@2.20.0 : Verbose - Auth code client created
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : [55e92e0d-a9d6-4939-b4d9-10820922389a] : msal.js.browser@2.20.0 : Verbose - validateAndExtractStateFromHash called
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : [55e92e0d-a9d6-4939-b4d9-10820922389a] : msal.js.browser@2.20.0 : Verbose - Returning state from hash
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : [55e92e0d-a9d6-4939-b4d9-10820922389a] : msal.js.browser@2.20.0 : Verbose - InteractionHandler.handleCodeResponse called
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : @azure/msal-browser@2.20.0 : Info - Emitting event: msal:ssoSilentFailure
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : @azure/msal-browser@2.20.0 : Verbose - Emitting event to callback c90edf90-4821-4265-96f1-cc767d8a980c: msal:ssoSilentFailure
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : @azure/msal-browser@2.20.0 : Verbose - getAllAccounts called
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : @azure/msal-react@1.1.2 : Info - MsalProvider - no account changes
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : @azure/msal-browser@2.20.0 : Verbose - Emitting event to callback 3961faf2-96c8-4b41-ba61-b2e5fc02f8d4: msal:ssoSilentFailure
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : @azure/msal-react@1.1.2 : Info - MsalProvider - msal:ssoSilentFailure results in setting inProgress from ssoSilent to none
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : @azure/msal-browser@2.20.0 : Verbose - getAllAccounts called
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : @azure/msal-browser@2.20.0 : Verbose - Emitting event to callback b441eb38-965b-44b4-a36e-e437e1c21cdf: msal:ssoSilentFailure
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : @azure/msal-browser@2.20.0 : Verbose - Emitting event to callback 05e96fa7-8d01-4bea-a405-c3542688d4d6: msal:ssoSilentFailure
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : @azure/msal-browser@2.20.0 : Verbose - getAllAccounts called
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : @azure/msal-browser@2.20.0 : Verbose - getAllAccounts called
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : @azure/msal-browser@2.20.0 : Verbose - getAllAccounts called
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : @azure/msal-react@1.1.2 : Verbose - useMsalAuthentication - Calling loginRedirect
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : @azure/msal-browser@2.20.0 : Verbose - loginRedirect called
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : @azure/msal-browser@2.20.0 : Verbose - preflightBrowserEnvironmentCheck started
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : @azure/msal-browser@2.20.0 : Verbose - acquireTokenRedirect called
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : @azure/msal-browser@2.20.0 : Verbose - getAllAccounts called
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : @azure/msal-browser@2.20.0 : Info - Emitting event: msal:loginStart
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : @azure/msal-browser@2.20.0 : Verbose - Emitting event to callback c90edf90-4821-4265-96f1-cc767d8a980c: msal:loginStart
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : @azure/msal-browser@2.20.0 : Verbose - Emitting event to callback 3961faf2-96c8-4b41-ba61-b2e5fc02f8d4: msal:loginStart
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : @azure/msal-react@1.1.2 : Info - MsalProvider - msal:loginStart results in setting inProgress from none to login
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : @azure/msal-browser@2.20.0 : Verbose - Emitting event to callback b441eb38-965b-44b4-a36e-e437e1c21cdf: msal:loginStart
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : @azure/msal-browser@2.20.0 : Verbose - Emitting event to callback 05e96fa7-8d01-4bea-a405-c3542688d4d6: msal:loginStart
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : [c35e1db7-3bfd-4c36-8b28-c973663f2268] : msal.js.browser@2.20.0 : Verbose - preflightInteractiveRequest called, validating app environment
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : [c35e1db7-3bfd-4c36-8b28-c973663f2268] : msal.js.browser@2.20.0 : Verbose - initializeAuthorizationRequest called
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : [c35e1db7-3bfd-4c36-8b28-c973663f2268] : msal.js.browser@2.20.0 : Verbose - getRedirectUri called
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : [c35e1db7-3bfd-4c36-8b28-c973663f2268] : msal.js.browser@2.20.0 : Verbose - Initializing BaseAuthRequest
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : [c35e1db7-3bfd-4c36-8b28-c973663f2268] : msal.js.browser@2.20.0 : Verbose - Authentication Scheme wasn't explicitly set in request, defaulting to "Bearer" request
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : [c35e1db7-3bfd-4c36-8b28-c973663f2268] : msal.js.browser@2.20.0 : Verbose - initializeServerTelemetryManager called
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : [c35e1db7-3bfd-4c36-8b28-c973663f2268] : msal.js.browser@2.20.0 : Verbose - initializeAuthorizationRequest called
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : @azure/msal-browser@2.20.0 : Verbose - getAllAccounts called
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : [c35e1db7-3bfd-4c36-8b28-c973663f2268] : msal.js.browser@2.20.0 : Verbose - getClientConfiguration called
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : [c35e1db7-3bfd-4c36-8b28-c973663f2268] : msal.js.browser@2.20.0 : Verbose - getDiscoveredAuthority called
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : [c35e1db7-3bfd-4c36-8b28-c973663f2268] : msal.js.browser@2.20.0 : Verbose - Creating discovered authority with request authority
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : [c35e1db7-3bfd-4c36-8b28-c973663f2268] : msal.js.browser@2.20.0 : Verbose - Auth code client created
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : [c35e1db7-3bfd-4c36-8b28-c973663f2268] : msal.js.browser@2.20.0 : Verbose - RedirectHandler.initiateAuthRequest called
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : [c35e1db7-3bfd-4c36-8b28-c973663f2268] : msal.js.browser@2.20.0 : Verbose - RedirectHandler.initiateAuthRequest: redirectStartPage set, caching start page
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : [c35e1db7-3bfd-4c36-8b28-c973663f2268] : msal.js.browser@2.20.0 : Verbose - RedirectHandler.initiateAuthRequest: Navigating window to navigate url
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : @azure/msal-browser@2.20.0 : Verbose - getAllAccounts called
[Log] [Wed, 08 Dec 2021 18:14:50 GMT] : @azure/msal-browser@2.20.0 : Verbose - getAllAccounts called
[Warning] Invalid HMR message: {"action":"sync","hash":"4a5e27464e5e8db3","warnings":[],"errors":[]}
Error: No router instance found.
You should only use "next/router" on the client side of your app.
...

MSAL Configuration

export const msalConfig: Configuration = {
  auth: {
    clientId: ..., // This is the ONLY mandatory field; everything else is optional.
    authority: ..., // Choose sign-up/sign-in user-flow as your default.
    redirectUri: ..., // You must register this URI on Azure Portal/App Registration. Defaults to "window.location.href".
    knownAuthorities: [...],
  },
  cache: {
    cacheLocation: "localStorage", // Configures cache location. "sessionStorage" is more secure, but "localStorage" gives you SSO between tabs.
    storeAuthStateInCookie: false, // If you wish to store cache items in cookies as well as browser cache, set this to "true".
  },
  // Uncomment to debug authentication
  system: {
    loggerOptions: {
      logLevel: LogLevel.Verbose,
      loggerCallback: (_, message) => console.log(message),
    },
  },
};

Relevant Code Snippets

useAuth.tsx

// Set up MSAL application instance. We do this at parse time so we can share this object
// outside of hooks. Useful for `getAuthenticatedHeaders` helper function.
const pca = new PublicClientApplication(msalConfig);

function B2CAuthProvider({ children }: B2CAuthProviderProps) {
  // Use custom routing for a smoother post-redirect experience
  const router = useRouter();
  const navigationClient = new CustomNavigationClient(router);
  pca.setNavigationClient(navigationClient);

  // Set up initial render hooks
  useEffect(() => {
    // Default to using the first account if no account is active on page load
    if (!pca.getActiveAccount() && pca.getAllAccounts().length > 0) {
      // Account selection logic is app dependent. Adjust as needed for different use cases.
      pca.setActiveAccount(pca.getAllAccounts()[0]);
    }

    // Optional - This will update account state if a user signs in from another tab or window
    pca.enableAccountStorageEvents();

    // Set the active account whenever the user logs in to a new account or fetches a new token
    // Note: Unfortunately this does not trigger a rerender off of `useMsal`, so we have to dupe
    // the work in our useAuthenticationRequired hook. Be careful when trying to authenticate
    // outside of a page with that hook as the account might not get set.
    pca.addEventCallback(event => {
      if (
        event.eventType === EventType.LOGIN_SUCCESS &&
        event.payload &&
        "homeAccountId" in event.payload
      ) {
        pca.setActiveAccount(event.payload);
      }

      if (
        [
          EventType.SSO_SILENT_SUCCESS,
          EventType.ACQUIRE_TOKEN_SUCCESS,
        ].includes(event.eventType) &&
        event.payload &&
        "account" in event.payload &&
        event.payload.account
      ) {
        pca.setActiveAccount(event.payload.account!);
      }
    });
  }, []);

  return <MsalProvider instance={pca}>{children}</MsalProvider>;
}

// Check if a user is logged in. If not, attempt to redirect.
export function useAuthenticationRequired() {
  // Attempt to silently login, if user already has a session on the server
  const { error, login } = useMsalAuthentication(
    InteractionType.Silent,
    loginRequest
  );

  // It failed, use the redirect flow to login
  useEffect(() => {
    if (error) {
      login(InteractionType.Redirect, loginRequest);
    }
  }, [error, login]);
}

example.tsx

export default function Example() {
  useAuthenticationRequired();
  return <div />;
}

Screen Shot 2021-12-08 at 10 27 02 AM

app-setup

Reproduction Steps

  1. Open URL to page using useAuthenticationRequired in mobile Safari with ITP enabled.
  2. Log in when redirected.
  3. Page will redirect loop.

Expected Behavior

Should get logged in & not redirect loop.

Identity Provider

Azure B2C Basic Policy

Browsers Affected (Select all that apply)

Safari

Regression

No response

Source

External (Customer)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
tomlagiercommented, Dec 8, 2021

Success! Working flawlessly, peer bonuses all around.

Thanks so much for your help all. When I’d set up the auth a couple months ago I was seeing LOGIN_SUCCESS as having the AccountInfo properties, but could definitely have been user error.

1reaction
tnorlingcommented, Dec 8, 2021

@tomlagier The response from the redirect isn’t being processed. handleRedirectPromise is just ending after attempting to navigate back to the starting page, meaning there’s a problem with the client side routing/navigation here. I see an error in your previous logs regarding the router instance not being available, can you double check that. Can you also please share your CustomNavigationClient implementation?

Read more comments on GitHub >

github_iconTop Results From Across the Web

NextJS custom router: iOS Safari redirect loop when ITP enabled
NextJS custom router : iOS Safari redirect loop when ITP enabled. Issue Template Bot #1130 #1130. Sign in to view logs · Sign...
Read more >
Safari nextjs redirect drops hash and query on prod build
If I use router. push or Link from next/link instead, hash is still there, but page is loaded twice.
Read more >
How to Fix: Safari too many redirects occurred? - BrowserHow
Learn how to fix the error Safari cannot open the page because too many redirect occurred error message. Clear cache and storage, ...
Read more >
Server-side Tagging In Google Tag Manager - Simo Ahava
An introduction to Server-side tagging in Google Tag Manager. The article contains examples and walkthroughs for getting started with the ...
Read more >
Safari Technology Preview Release Notes - Apple Developer
Release 160. Note: Shared Tab Groups and syncing for Tab Groups, Website Settings, and Web Extensions are not enabled in this release. Web...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found