'Azure AD B2C with MSAL change redirect url on success

I have a React app which uses MSAL msal-react v1.3.1. I am using loginRedirect method to redirect a predefined user flow configured in Azure B2C for password reset. The current behaviour is that when the password reset is complete it redirects back to the page that first invoked the redirect to AD B2C once it has completed successfully.

Is there a way to change the redirect url when the flow has completed to something like below?

instance.loginRedirect({
    authority: `${config.authentication.authority}/${config.authentication.flow.register}`,
    redirectUri: window.location.href + '?success=true'
});

I have tried to set the redirectUri and postLoginRedirectUri which don't appear to change the outcome.



Solution 1:[1]

There appears to be a restriction on the redirectUrl as described here.

The redirect url must be registered with the application and cannot contain wildcards or query string parameters.

Solution 2:[2]

What I had to do in this situation was set the navigateToLoginRequestUrl to false where you set up your msal. Example of someone's code with the navigateToLoginRequestUrl option: https://github.com/AzureAD/microsoft-authentication-library-for-js/issues/3818

Then maybe you could use the state option to pass any information you want to the return URL instead of a query parameter on returnURL. But I don't quite see the point here.

instance.loginRedirect({
        authority: `${config.authentication.authority}/${config.authentication.flow.register}`,
        redirectUri: window.location.href,
        state: 'success'
});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sharifxu
Solution 2 MattyMoo21