Skip to content

Commit b210a96

Browse files
authored
feat(experience): always include app_id in search params on router navigation (#7950)
* feat(experience): always include app_id in search params on router navigation * fix: tests
1 parent 1fb7d53 commit b210a96

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+172
-85
lines changed

packages/experience/src/components/IdentifierRegisterForm/index.test.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,10 @@ describe('<IdentifierRegisterForm />', () => {
442442
});
443443

444444
await waitFor(() => {
445-
expect(mockedNavigate).toBeCalledWith(`/${experience.routes.sso}/connectors`);
445+
expect(mockedNavigate).toBeCalledWith(
446+
{ pathname: `/${experience.routes.sso}/connectors` },
447+
undefined
448+
);
446449
});
447450
});
448451
});

packages/experience/src/components/IdentifierRegisterForm/use-register-with-username.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import { InteractionEvent } from '@logto/schemas';
22
import { useState, useCallback, useMemo, useContext } from 'react';
3-
import { useNavigate } from 'react-router-dom';
43

54
import CaptchaContext from '@/Providers/CaptchaContextProvider/CaptchaContext';
65
import { identifyAndSubmitInteraction, registerWithUsername } from '@/apis/experience';
76
import useApi from '@/hooks/use-api';
87
import type { ErrorHandlers } from '@/hooks/use-error-handler';
98
import useErrorHandler from '@/hooks/use-error-handler';
109
import useGlobalRedirectTo from '@/hooks/use-global-redirect-to';
10+
import useNavigateWithPreservedSearchParams from '@/hooks/use-navigate-with-preserved-search-params';
1111
import { useSieMethods } from '@/hooks/use-sie';
1212
import useSubmitInteractionErrorHandler from '@/hooks/use-submit-interaction-error-handler';
1313

1414
const useRegisterWithUsername = () => {
15-
const navigate = useNavigate();
15+
const navigate = useNavigateWithPreservedSearchParams();
1616
const redirectTo = useGlobalRedirectTo();
1717
const { executeCaptcha } = useContext(CaptchaContext);
1818

packages/experience/src/components/IdentifierSignInForm/index.test.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ describe('IdentifierSignInForm', () => {
128128
if (identifier === SignInIdentifier.Username) {
129129
await waitFor(() => {
130130
expect(sendVerificationCodeApi).not.toBeCalled();
131-
expect(mockedNavigate).toBeCalledWith({ pathname: '/sign-in/password' });
131+
expect(mockedNavigate).toBeCalledWith({ pathname: '/sign-in/password' }, undefined);
132132
});
133133

134134
return;
@@ -143,7 +143,7 @@ describe('IdentifierSignInForm', () => {
143143
if (password && (isPasswordPrimary || !verificationCode)) {
144144
await waitFor(() => {
145145
expect(sendVerificationCodeApi).not.toBeCalled();
146-
expect(mockedNavigate).toBeCalledWith({ pathname: '/sign-in/password' });
146+
expect(mockedNavigate).toBeCalledWith({ pathname: '/sign-in/password' }, undefined);
147147
});
148148

149149
return;
@@ -195,7 +195,7 @@ describe('IdentifierSignInForm', () => {
195195

196196
await waitFor(() => {
197197
expect(getSingleSignOnConnectorsMock).not.toBeCalled();
198-
expect(mockedNavigate).toBeCalledWith({ pathname: '/sign-in/password' });
198+
expect(mockedNavigate).toBeCalledWith({ pathname: '/sign-in/password' }, undefined);
199199
});
200200
});
201201

@@ -222,7 +222,7 @@ describe('IdentifierSignInForm', () => {
222222

223223
await waitFor(() => {
224224
expect(getSingleSignOnConnectorsMock).not.toBeCalled();
225-
expect(mockedNavigate).toBeCalledWith({ pathname: '/sign-in/password' });
225+
expect(mockedNavigate).toBeCalledWith({ pathname: '/sign-in/password' }, undefined);
226226
});
227227
});
228228

@@ -256,7 +256,7 @@ describe('IdentifierSignInForm', () => {
256256
});
257257

258258
await waitFor(() => {
259-
expect(mockedNavigate).toBeCalledWith({ pathname: '/sign-in/password' });
259+
expect(mockedNavigate).toBeCalledWith({ pathname: '/sign-in/password' }, undefined);
260260
});
261261
});
262262

@@ -294,7 +294,10 @@ describe('IdentifierSignInForm', () => {
294294
});
295295

296296
await waitFor(() => {
297-
expect(mockedNavigate).toBeCalledWith(`/${experience.routes.sso}/connectors`);
297+
expect(mockedNavigate).toBeCalledWith(
298+
{ pathname: `/${experience.routes.sso}/connectors` },
299+
undefined
300+
);
298301
});
299302
});
300303
});

packages/experience/src/components/IdentifierSignInForm/use-on-submit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import type { SignIn } from '@logto/schemas';
22
import { SignInIdentifier } from '@logto/schemas';
33
import { useCallback, useContext } from 'react';
4-
import { useNavigate } from 'react-router-dom';
54

65
import UserInteractionContext from '@/Providers/UserInteractionContextProvider/UserInteractionContext';
76
import useCheckSingleSignOn from '@/hooks/use-check-single-sign-on';
7+
import useNavigateWithPreservedSearchParams from '@/hooks/use-navigate-with-preserved-search-params';
88
import useSendVerificationCode from '@/hooks/use-send-verification-code';
99
import { useSieMethods } from '@/hooks/use-sie';
1010
import { UserFlow } from '@/types';
1111

1212
const useOnSubmit = (signInMethods: SignIn['methods']) => {
13-
const navigate = useNavigate();
13+
const navigate = useNavigateWithPreservedSearchParams();
1414
const { ssoConnectors } = useSieMethods();
1515
const { onSubmit: checkSingleSignOn } = useCheckSingleSignOn();
1616
const { setIdentifierInputValue } = useContext(UserInteractionContext);

packages/experience/src/components/NavBar/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import classNames from 'classnames';
22
import { useCallback } from 'react';
33
import { useTranslation } from 'react-i18next';
4-
import { useNavigate } from 'react-router-dom';
54

65
import ArrowPrev from '@/assets/icons/arrow-prev.svg?react';
76
import NavClose from '@/assets/icons/nav-close.svg?react';
7+
import useNavigateWithPreservedSearchParams from '@/hooks/use-navigate-with-preserved-search-params';
88
import { onKeyDownHandler } from '@/utils/a11y';
99

1010
import FlipOnRtl from '../FlipOnRtl';
@@ -20,7 +20,7 @@ type Props = {
2020
};
2121

2222
const NavBar = ({ title, type = 'back', isHidden, onClose, onSkip }: Props) => {
23-
const navigate = useNavigate();
23+
const navigate = useNavigateWithPreservedSearchParams();
2424
const { t } = useTranslation();
2525

2626
const isClosable = type === 'close';

packages/experience/src/components/PasswordSignInForm/index.test.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,10 @@ describe('UsernamePasswordSignInForm', () => {
267267
});
268268

269269
await waitFor(() => {
270-
expect(mockedNavigate).toBeCalledWith(`/${experience.routes.sso}/connectors`);
270+
expect(mockedNavigate).toBeCalledWith(
271+
{ pathname: `/${experience.routes.sso}/connectors` },
272+
undefined
273+
);
271274
});
272275
});
273276

packages/experience/src/containers/ForgotPasswordLink/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { SignInIdentifier } from '@logto/schemas';
22
import { useContext } from 'react';
3-
import { useNavigate } from 'react-router-dom';
43

54
import UserInteractionContext from '@/Providers/UserInteractionContextProvider/UserInteractionContext';
65
import TextLink from '@/components/TextLink';
6+
import useNavigateWithPreservedSearchParams from '@/hooks/use-navigate-with-preserved-search-params';
77
import { UserFlow } from '@/types';
88

99
type Props = {
@@ -13,7 +13,7 @@ type Props = {
1313
};
1414

1515
const ForgotPasswordLink = ({ className, ...identifierData }: Props) => {
16-
const navigate = useNavigate();
16+
const navigate = useNavigateWithPreservedSearchParams();
1717
const { setForgotPasswordIdentifierInputValue } = useContext(UserInteractionContext);
1818

1919
return (

packages/experience/src/containers/MfaFactorList/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { MfaFactor, SignInIdentifier } from '@logto/schemas';
22
import { useCallback } from 'react';
3-
import { useNavigate } from 'react-router-dom';
43

54
import MfaFactorButton from '@/components/Button/MfaFactorButton';
5+
import useNavigateWithPreservedSearchParams from '@/hooks/use-navigate-with-preserved-search-params';
66
import useSendMfaVerificationCode from '@/hooks/use-send-mfa-verification-code';
77
import useStartTotpBinding from '@/hooks/use-start-totp-binding';
88
import useStartWebAuthnProcessing from '@/hooks/use-start-webauthn-processing';
@@ -19,7 +19,7 @@ type Props = {
1919
const MfaFactorList = ({ flow, flowState }: Props) => {
2020
const startTotpBinding = useStartTotpBinding();
2121
const startWebAuthnProcessing = useStartWebAuthnProcessing();
22-
const navigate = useNavigate();
22+
const navigate = useNavigateWithPreservedSearchParams();
2323
const { availableFactors } = flowState;
2424
const { onSubmit: sendMfaVerificationCode } = useSendMfaVerificationCode();
2525

packages/experience/src/containers/VerificationCode/use-continue-flow-code-verification.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { VerificationCodeIdentifier } from '@logto/schemas';
22
import { InteractionEvent, MfaFactor, VerificationType } from '@logto/schemas';
33
import { useCallback, useContext, useMemo } from 'react';
4-
import { useLocation, useNavigate, useSearchParams } from 'react-router-dom';
4+
import { useLocation, useSearchParams } from 'react-router-dom';
55
import { validate } from 'superstruct';
66

77
import UserInteractionContext from '@/Providers/UserInteractionContextProvider/UserInteractionContext';
@@ -12,6 +12,7 @@ import useApi from '@/hooks/use-api';
1212
import type { ErrorHandlers } from '@/hooks/use-error-handler';
1313
import useErrorHandler from '@/hooks/use-error-handler';
1414
import useGlobalRedirectTo from '@/hooks/use-global-redirect-to';
15+
import useNavigateWithPreservedSearchParams from '@/hooks/use-navigate-with-preserved-search-params';
1516
import { useSieMethods } from '@/hooks/use-sie';
1617
import useSubmitInteractionErrorHandler from '@/hooks/use-submit-interaction-error-handler';
1718
import useToast from '@/hooks/use-toast';
@@ -30,7 +31,7 @@ const useContinueFlowCodeVerification = (
3031
) => {
3132
const [searchParameters] = useSearchParams();
3233
const redirectTo = useGlobalRedirectTo();
33-
const navigate = useNavigate();
34+
const navigate = useNavigateWithPreservedSearchParams();
3435

3536
const { state } = useLocation();
3637
const { verificationIdsMap } = useContext(UserInteractionContext);

packages/experience/src/containers/VerificationCode/use-forgot-password-flow-code-verification.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import type { VerificationCodeIdentifier } from '@logto/schemas';
22
import { useCallback, useMemo } from 'react';
3-
import { useNavigate } from 'react-router-dom';
43

54
import { identifyWithVerificationCode } from '@/apis/experience';
65
import useApi from '@/hooks/use-api';
76
import type { ErrorHandlers } from '@/hooks/use-error-handler';
87
import useErrorHandler from '@/hooks/use-error-handler';
8+
import useNavigateWithPreservedSearchParams from '@/hooks/use-navigate-with-preserved-search-params';
99
import { UserFlow } from '@/types';
1010

1111
import useGeneralVerificationCodeErrorHandler from './use-general-verification-code-error-handler';
@@ -16,7 +16,7 @@ const useForgotPasswordFlowCodeVerification = (
1616
verificationId: string,
1717
errorCallback?: () => void
1818
) => {
19-
const navigate = useNavigate();
19+
const navigate = useNavigateWithPreservedSearchParams();
2020
const handleError = useErrorHandler();
2121
const verifyVerificationCode = useApi(identifyWithVerificationCode);
2222

0 commit comments

Comments
 (0)