diff --git a/packages/react/src/FronteggProvider.tsx b/packages/react/src/FronteggProvider.tsx index 1c365574..2f382d13 100644 --- a/packages/react/src/FronteggProvider.tsx +++ b/packages/react/src/FronteggProvider.tsx @@ -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'; @@ -26,6 +26,16 @@ export const ConnectorHistory: FC> = (props) => return ; }; +/** + * @param path path to check + * @param routes frontegg auth routes + * @returns true when should bypass react router + */ +function isBypassReactRoute(path: string, routes?: Partial) { + const stepUpUrl = routes?.stepUpUrl; + return stepUpUrl && path.startsWith(stepUpUrl); +} + export const Connector: FC = ({ history, appName, isExternalHistory = false, ...props }) => { const isSSR = typeof window === 'undefined'; const version = `@frontegg/react@${sdkVersion.version}`; @@ -48,8 +58,7 @@ export const Connector: FC = ({ history, appName, isExternalHist path = `${path}${window.location.search}`; } - const stepUpUrl = props.authOptions?.routes?.stepUpUrl; - if (stepUpUrl && path.startsWith(stepUpUrl)) { + 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;