Skip to content

Commit

Permalink
pr
Browse files Browse the repository at this point in the history
  • Loading branch information
doregg committed Dec 14, 2023
1 parent 30ee670 commit 8c99ecf
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions 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 @@ -48,8 +58,7 @@ export const Connector: FC<ConnectorProps> = ({ 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;
Expand Down

0 comments on commit 8c99ecf

Please sign in to comment.