Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use navigate fn to redirect to reset pw page in ep+pwless combo #863

Merged
merged 1 commit into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [0.48.0] - 2024-10-07

### Fixes

- 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.

### Changes

- Added the `OAuth2Provider` recipe
Expand Down
28 changes: 18 additions & 10 deletions lib/build/passwordlessprebuiltui.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions lib/build/recipe/passwordless/types.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/build/recipe/recipeModule/index.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ export function useChildProps(
recipeImplementation: recipeImplementation,
config: recipe.config,
validatePhoneNumber: recipe.config.validatePhoneNumber ?? defaultPhoneNumberValidator,
navigate,
};
}, [
error,
Expand All @@ -242,6 +243,7 @@ export function useChildProps(
isPhoneNumber,
showPasswordField,
showContinueWithPasswordlessLink,
navigate,
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ export const EPComboEmailForm = withOverride(
<Label value={"PWLESS_COMBO_PASSWORD_LABEL"} data-supertokens="passwordInputLabel" />
<a
onClick={() =>
EmailPassword.getInstanceOrThrow().redirect({
action: "RESET_PASSWORD",
tenantIdFromQueryParams: getTenantIdFromQueryParams(),
})
EmailPassword.getInstanceOrThrow().redirect(
{
action: "RESET_PASSWORD",
tenantIdFromQueryParams: getTenantIdFromQueryParams(),
},
props.navigate
)
}
data-supertokens="link linkButton formLabelLinkBtn forgotPasswordLink">
{t("PWLESS_COMBO_FORGOT_PW_LINK")}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,13 @@ export const EPComboEmailOrPhoneForm = withOverride(
<Label value={"PWLESS_COMBO_PASSWORD_LABEL"} data-supertokens="passwordInputLabel" />
<a
onClick={() =>
EmailPassword.getInstanceOrThrow().redirect({
action: "RESET_PASSWORD",
tenantIdFromQueryParams: getTenantIdFromQueryParams(),
})
EmailPassword.getInstanceOrThrow().redirect(
{
action: "RESET_PASSWORD",
tenantIdFromQueryParams: getTenantIdFromQueryParams(),
},
props.navigate
)
}
data-supertokens="link linkButton formLabelLinkBtn forgotPasswordLink">
{t("PWLESS_COMBO_FORGOT_PW_LINK")}
Expand Down
4 changes: 4 additions & 0 deletions lib/ts/recipe/passwordless/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import type { ComponentOverride } from "../../components/componentOverride/compo
import type {
APIFormField,
FeatureBaseConfig,
Navigate,
NormalisedBaseConfig,
UserContext,
WebJSRecipeInterface,
Expand Down Expand Up @@ -307,6 +308,7 @@ export type SignInUpEPComboEmailOrPhoneFormProps = {
recipeImplementation: RecipeImplementation;
config: NormalisedConfig;
validatePhoneNumber: (phoneNumber: string) => Promise<string | undefined> | string | undefined;
navigate: Navigate | undefined;
};

export type SignInUpEPComboEmailFormProps = {
Expand All @@ -327,6 +329,7 @@ export type SignInUpEPComboEmailFormProps = {
recipeImplementation: RecipeImplementation;
validatePhoneNumber: (phoneNumber: string) => Promise<string | undefined> | string | undefined;
config: NormalisedConfig;
navigate: Navigate | undefined;
};

export type MFAAction =
Expand Down Expand Up @@ -381,6 +384,7 @@ export type SignInUpEPComboChildProps = Omit<SignInUpProps, "onSuccess"> & {
| { status: "OK"; isEmailPassword: false | undefined }
) => void;
validatePhoneNumber: (phoneNumber: string) => Promise<string | undefined> | string | undefined;
navigate: Navigate | undefined;
};
export type LinkSentChildProps = LinkSentThemeProps;
export type MFAChildProps = Omit<MFAProps, "featureState" | "dispatch">;
Expand Down
2 changes: 1 addition & 1 deletion lib/ts/recipe/recipeModule/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default abstract class RecipeModule<
> extends BaseRecipeModule<GetRedirectionURLContextType, Action, OnHandleEventContextType, N> {
redirect = async (
context: NormalisedGetRedirectionURLContext<GetRedirectionURLContextType>,
navigate?: Navigate,
navigate: Navigate | undefined,
queryParams?: Record<string, string>,
userContext?: UserContext
): Promise<void> => {
Expand Down
32 changes: 32 additions & 0 deletions test/end-to-end/passwordless.test_gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
backendBeforeEach,
waitForUrl,
setupBrowser,
clickForgotPasswordLink,
} from "../helpers";

import { TEST_CLIENT_BASE_URL, TEST_SERVER_BASE_URL, SOMETHING_WENT_WRONG_ERROR } from "../constants";
Expand Down Expand Up @@ -1866,6 +1867,37 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe
await waitForSTElement(page, "[data-supertokens~=input][name=userInputCode]");
});
});

if (authRecipe === "all") {
describe("with emailpassword combo", () => {
before(async function () {
({ browser, page } = await initBrowser(contactMethod, consoleLogs, authRecipe));
await setPasswordlessFlowType(contactMethod, "USER_INPUT_CODE");
if (authRecipe === "all") {
await tryEmailPasswordSignUp(page, registeredEmailWithPass);
}
});

it("should navigate to the sign in page when the user clicks on the forgot password link", async function () {
await page.goto(`${TEST_CLIENT_BASE_URL}/auth`);

await setInputValues(page, [{ name: "email", value: registeredEmailWithPass }]);
await submitForm(page);

const testVal = "nav check" + Date.now();

await page.evaluate((testVal) => {
window.testVal = testVal;
}, testVal);

await clickForgotPasswordLink(page);
await waitForUrl(page, "/auth/reset-password");

const testValAfterNav = await page.evaluate(() => window.testVal);
assert.strictEqual(testVal, testValAfterNav);
});
});
}
}
}

Expand Down
Loading