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

feat: Adds signInFeature type and validation for form fields in EmailPassword Recipe #976

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

vitusan
Copy link

@vitusan vitusan commented Feb 17, 2025

Summary of change

Introduce a new signInFeature type with validation for form fields, ensuring proper handling of email and password fields. Update related functions to accommodate the new feature. Why? Because my use case needs to send additional data to the SignIn POST endpoint and that made things complicated for the only way to achieve this was to override the SignInPost.

Related issues

Test Plan

npm run test. All tests have passed.

Documentation changes

  • Mention in EmailPassword Recipe that is also possible to change the signIn Form fields, not just the signUp Form fields.

Checklist for important updates

  • Changelog has been updated
  • coreDriverInterfaceSupported.json file has been updated (if needed)
    • Along with the associated array in lib/ts/version.ts
  • frontendDriverInterfaceSupported.json file has been updated (if needed)
  • Changes to the version if needed
    • In package.json
    • In package-lock.json
    • In lib/ts/version.ts
  • Had run npm run build-pretty
  • Had installed and ran the pre-commit hook
  • If new thirdparty provider is added,
    • update switch statement in recipe/thirdparty/providers/configUtils.ts file, createProvider function.
    • add an icon on the user management dashboard.
  • Issue this PR against the latest non released version branch.
    • To know which one it is, run find the latest released tag (git tag) in the format vX.Y.Z, and then find the latest branch (git branch --all) whose X.Y is greater than the latest released tag.
    • If no such branch exists, then create one from the latest released branch.
  • If have added a new web framework, update the add-ts-no-check.js file to include that
  • If added a new recipe / api interface, then make sure that the implementation of it uses NON arrow functions only (like someFunc: function () {..}).
  • If added a new recipe, then make sure to expose it inside the recipe folder present in the root of this repo. We also need to expose its types.
  • If added a new entry point, then make sure that it is importable by adding it to the exports in package.json

Remaining TODOs for this PR

Copy link

netlify bot commented Feb 17, 2025

Deploy Preview for precious-marshmallow-968a81 canceled.

Name Link
🔨 Latest commit 8722640
🔍 Latest deploy log https://app.netlify.com/sites/precious-marshmallow-968a81/deploys/67b27e6e5582720008bf2781

Copy link

netlify bot commented Feb 17, 2025

Deploy Preview for astounding-pegasus-21c111 canceled.

Name Link
🔨 Latest commit 8722640
🔍 Latest deploy log https://app.netlify.com/sites/astounding-pegasus-21c111/deploys/67b27e6ed9f17900081a25f1

@@ -12,7 +12,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
export const version = "21.1.0";
export const version = "21.1.1";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be a minor (not patch) level change.

validate: field.id === FORM_FIELD_EMAIL_ID ? field.validate : defaultValidator,
optional: false,
};
function normaliseSignInFormFields(formFields?: TypeInputFormField[]) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If done this way, it'd be a breaking change: if someone added an override for their email validators in the sign up config, they'd expect it to be applied here. I'd prefer if we kept it that way as well.

if (field.id === FORM_FIELD_PASSWORD_ID) {
normalisedFormFields.push({
id: field.id,
validate: field.validate === undefined ? defaultPasswordValidator : field.validate,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, you shouldn't have a validator for the password field during sign-in, since we'd want to check the DB in most cases anyway to prevent cases where a password validation change is preventing people from logging in. I don't mind giving people the option to define this specifically, but by default it should let everything pass.

Suggested change
validate: field.validate === undefined ? defaultPasswordValidator : field.validate,
validate: field.validate === undefined ? defaultValidator : field.validate,

});
}
if (normalisedFormFields.filter((field) => field.id === FORM_FIELD_PASSWORD_ID).length === 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (normalisedFormFields.filter((field) => field.id === FORM_FIELD_PASSWORD_ID).length === 0) {
if (!normalisedFormFields.some((field) => field.id === FORM_FIELD_PASSWORD_ID)) {

optional: false,
});
}
if (normalisedFormFields.filter((field) => field.id === FORM_FIELD_EMAIL_ID).length === 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (normalisedFormFields.filter((field) => field.id === FORM_FIELD_EMAIL_ID).length === 0) {
if (!normalisedFormFields.some((field) => field.id === FORM_FIELD_EMAIL_ID)) {

// no password field give by user
normalisedFormFields.push({
id: FORM_FIELD_PASSWORD_ID,
validate: defaultPasswordValidator,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
validate: defaultPasswordValidator,
validate: defaultValidator,

// no email field give by user
normalisedFormFields.push({
id: FORM_FIELD_EMAIL_ID,
validate: defaultEmailValidator,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should fall back to the (normalized) email field validator for sign-up to avoid breaking apps.

@porcellus
Copy link
Collaborator

Hi, thanks for your contribution. I think we should be able to get this merged and released next week :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants