Skip to content

Commit

Permalink
Merge pull request #1077 from frontegg/FR-14232-stepup-onredirecturl-…
Browse files Browse the repository at this point in the history
…support

FR-14232 - Step up onRedirectTo support
  • Loading branch information
doregg authored Dec 20, 2023
2 parents f0673ee + 7246bb0 commit 79abbf2
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/react/src/FronteggProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FronteggStoreProvider } from '@frontegg/react-hooks';
import { BrowserRouter, useHistory, UseHistory } from './routerProxy';
import { ContextHolder, RedirectOptions, FronteggFrameworks } from '@frontegg/rest-api';
import { AppHolder } from '@frontegg/js/AppHolder';
import { isAuthRoute } from '@frontegg/redux-store';
import { isAuthRoute, AuthPageRoutes } from '@frontegg/redux-store';
import sdkVersion from './sdkVersion';
import ReactPkg from 'react/package.json';
import { AlwaysRenderInProvider, HistoryObject } from './AlwaysRenderInProvider';
Expand All @@ -26,6 +26,16 @@ export const ConnectorHistory: FC<Omit<ConnectorProps, 'history'>> = (props) =>
return <Connector history={history} {...props} />;
};

/**
* @param path path to check
* @param routes frontegg auth routes
* @returns true when should bypass react router
*/
function isBypassReactRoute(path: string, routes?: Partial<AuthPageRoutes>) {
const stepUpUrl = routes?.stepUpUrl;
return stepUpUrl && path.startsWith(stepUpUrl);
}

export const Connector: FC<ConnectorProps> = ({ history, appName, isExternalHistory = false, ...props }) => {
const isSSR = typeof window === 'undefined';
const version = `@frontegg/react@${sdkVersion.version}`;
Expand All @@ -47,6 +57,13 @@ export const Connector: FC<ConnectorProps> = ({ history, appName, isExternalHist
if (opts?.preserveQueryParams || isAuthRouteRef.current(path)) {
path = `${path}${window.location.search}`;
}

if (isBypassReactRoute(path, props.authOptions?.routes)) {
// when user app includes a fallback route, we need to avoid using the react router
window?.history?.pushState(null, '', path);
return;
}

if (opts?.refresh && !isSSR) {
// @ts-ignore
window.Cypress ? history.push(path) : (window.location.href = path);
Expand Down

0 comments on commit 79abbf2

Please sign in to comment.