Skip to content

Commit 9af4400

Browse files
authored
fix: use navigate fn to redirect to reset pw page in ep+pwless combo (#863)
1 parent 6a20133 commit 9af4400

File tree

10 files changed

+80
-20
lines changed

10 files changed

+80
-20
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
## [0.48.0] - 2024-10-07
1111

12+
### Fixes
13+
14+
- Fixed an issue where the `AuthPage` was using full-page redirects to navigate to the password reset page if both emailpassword and passwordless were enabled.
15+
1216
### Changes
1317

1418
- Added the `OAuth2Provider` recipe

lib/build/passwordlessprebuiltui.js

Lines changed: 18 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/build/recipe/passwordless/types.d.ts

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/build/recipe/recipeModule/index.d.ts

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/ts/recipe/passwordless/components/features/signInAndUpEPCombo/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ export function useChildProps(
233233
recipeImplementation: recipeImplementation,
234234
config: recipe.config,
235235
validatePhoneNumber: recipe.config.validatePhoneNumber ?? defaultPhoneNumberValidator,
236+
navigate,
236237
};
237238
}, [
238239
error,
@@ -242,6 +243,7 @@ export function useChildProps(
242243
isPhoneNumber,
243244
showPasswordField,
244245
showContinueWithPasswordlessLink,
246+
navigate,
245247
]);
246248
}
247249

lib/ts/recipe/passwordless/components/themes/signInUpEPCombo/emailForm.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,13 @@ export const EPComboEmailForm = withOverride(
5959
<Label value={"PWLESS_COMBO_PASSWORD_LABEL"} data-supertokens="passwordInputLabel" />
6060
<a
6161
onClick={() =>
62-
EmailPassword.getInstanceOrThrow().redirect({
63-
action: "RESET_PASSWORD",
64-
tenantIdFromQueryParams: getTenantIdFromQueryParams(),
65-
})
62+
EmailPassword.getInstanceOrThrow().redirect(
63+
{
64+
action: "RESET_PASSWORD",
65+
tenantIdFromQueryParams: getTenantIdFromQueryParams(),
66+
},
67+
props.navigate
68+
)
6669
}
6770
data-supertokens="link linkButton formLabelLinkBtn forgotPasswordLink">
6871
{t("PWLESS_COMBO_FORGOT_PW_LINK")}

lib/ts/recipe/passwordless/components/themes/signInUpEPCombo/emailOrPhoneForm.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,13 @@ export const EPComboEmailOrPhoneForm = withOverride(
109109
<Label value={"PWLESS_COMBO_PASSWORD_LABEL"} data-supertokens="passwordInputLabel" />
110110
<a
111111
onClick={() =>
112-
EmailPassword.getInstanceOrThrow().redirect({
113-
action: "RESET_PASSWORD",
114-
tenantIdFromQueryParams: getTenantIdFromQueryParams(),
115-
})
112+
EmailPassword.getInstanceOrThrow().redirect(
113+
{
114+
action: "RESET_PASSWORD",
115+
tenantIdFromQueryParams: getTenantIdFromQueryParams(),
116+
},
117+
props.navigate
118+
)
116119
}
117120
data-supertokens="link linkButton formLabelLinkBtn forgotPasswordLink">
118121
{t("PWLESS_COMBO_FORGOT_PW_LINK")}

lib/ts/recipe/passwordless/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import type { ComponentOverride } from "../../components/componentOverride/compo
3333
import type {
3434
APIFormField,
3535
FeatureBaseConfig,
36+
Navigate,
3637
NormalisedBaseConfig,
3738
UserContext,
3839
WebJSRecipeInterface,
@@ -307,6 +308,7 @@ export type SignInUpEPComboEmailOrPhoneFormProps = {
307308
recipeImplementation: RecipeImplementation;
308309
config: NormalisedConfig;
309310
validatePhoneNumber: (phoneNumber: string) => Promise<string | undefined> | string | undefined;
311+
navigate: Navigate | undefined;
310312
};
311313

312314
export type SignInUpEPComboEmailFormProps = {
@@ -327,6 +329,7 @@ export type SignInUpEPComboEmailFormProps = {
327329
recipeImplementation: RecipeImplementation;
328330
validatePhoneNumber: (phoneNumber: string) => Promise<string | undefined> | string | undefined;
329331
config: NormalisedConfig;
332+
navigate: Navigate | undefined;
330333
};
331334

332335
export type MFAAction =
@@ -381,6 +384,7 @@ export type SignInUpEPComboChildProps = Omit<SignInUpProps, "onSuccess"> & {
381384
| { status: "OK"; isEmailPassword: false | undefined }
382385
) => void;
383386
validatePhoneNumber: (phoneNumber: string) => Promise<string | undefined> | string | undefined;
387+
navigate: Navigate | undefined;
384388
};
385389
export type LinkSentChildProps = LinkSentThemeProps;
386390
export type MFAChildProps = Omit<MFAProps, "featureState" | "dispatch">;

lib/ts/recipe/recipeModule/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default abstract class RecipeModule<
3030
> extends BaseRecipeModule<GetRedirectionURLContextType, Action, OnHandleEventContextType, N> {
3131
redirect = async (
3232
context: NormalisedGetRedirectionURLContext<GetRedirectionURLContextType>,
33-
navigate?: Navigate,
33+
navigate: Navigate | undefined,
3434
queryParams?: Record<string, string>,
3535
userContext?: UserContext
3636
): Promise<void> => {

test/end-to-end/passwordless.test_gen.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
backendBeforeEach,
3939
waitForUrl,
4040
setupBrowser,
41+
clickForgotPasswordLink,
4142
} from "../helpers";
4243

4344
import { TEST_CLIENT_BASE_URL, TEST_SERVER_BASE_URL, SOMETHING_WENT_WRONG_ERROR } from "../constants";
@@ -1866,6 +1867,37 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe
18661867
await waitForSTElement(page, "[data-supertokens~=input][name=userInputCode]");
18671868
});
18681869
});
1870+
1871+
if (authRecipe === "all") {
1872+
describe("with emailpassword combo", () => {
1873+
before(async function () {
1874+
({ browser, page } = await initBrowser(contactMethod, consoleLogs, authRecipe));
1875+
await setPasswordlessFlowType(contactMethod, "USER_INPUT_CODE");
1876+
if (authRecipe === "all") {
1877+
await tryEmailPasswordSignUp(page, registeredEmailWithPass);
1878+
}
1879+
});
1880+
1881+
it("should navigate to the sign in page when the user clicks on the forgot password link", async function () {
1882+
await page.goto(`${TEST_CLIENT_BASE_URL}/auth`);
1883+
1884+
await setInputValues(page, [{ name: "email", value: registeredEmailWithPass }]);
1885+
await submitForm(page);
1886+
1887+
const testVal = "nav check" + Date.now();
1888+
1889+
await page.evaluate((testVal) => {
1890+
window.testVal = testVal;
1891+
}, testVal);
1892+
1893+
await clickForgotPasswordLink(page);
1894+
await waitForUrl(page, "/auth/reset-password");
1895+
1896+
const testValAfterNav = await page.evaluate(() => window.testVal);
1897+
assert.strictEqual(testVal, testValAfterNav);
1898+
});
1899+
});
1900+
}
18691901
}
18701902
}
18711903

0 commit comments

Comments
 (0)