diff --git a/app/(gcforms)/[locale]/(user authentication)/auth/login/actions.ts b/app/(gcforms)/[locale]/(user authentication)/auth/login/actions.ts index 6eade2b813..8f7183c917 100644 --- a/app/(gcforms)/[locale]/(user authentication)/auth/login/actions.ts +++ b/app/(gcforms)/[locale]/(user authentication)/auth/login/actions.ts @@ -6,6 +6,7 @@ import { redirect } from "next/navigation"; import { CognitoIdentityProviderServiceException } from "@aws-sdk/client-cognito-identity-provider"; import { hasError } from "@lib/hasError"; import { handleErrorById } from "@lib/auth/cognito"; +import { isValidGovEmail } from "@lib/validation/validation"; export interface ErrorStates { authError?: { @@ -37,7 +38,7 @@ const validate = async ( v.toLowerCase(), v.toTrimmed(), v.minLength(1, t("input-validation.required", { ns: "common" })), - v.email(t("input-validation.email", { ns: "common" })), + v.custom((input) => isValidGovEmail(input), t("input-validation.validGovEmail")), ]), password: v.string([ v.minLength(1, t("input-validation.required", { ns: "common" })), diff --git a/app/(gcforms)/[locale]/(user authentication)/auth/register/action.ts b/app/(gcforms)/[locale]/(user authentication)/auth/register/action.ts index 52c497f263..42121027a4 100644 --- a/app/(gcforms)/[locale]/(user authentication)/auth/register/action.ts +++ b/app/(gcforms)/[locale]/(user authentication)/auth/register/action.ts @@ -52,11 +52,7 @@ const validate = async ( v.toLowerCase(), v.toTrimmed(), v.minLength(1, t("input-validation.required", { ns: "common" })), - v.email(t("input-validation.email", { ns: "common" })), - v.custom( - (input) => isValidGovEmail(input), - t("signUpRegistration.fields.username.error.validGovEmail") - ), + v.custom((input) => isValidGovEmail(input), t("input-validation.validGovEmail")), ]), password: v.string([ v.minLength(1, t("input-validation.required", { ns: "common" })), diff --git a/app/(gcforms)/[locale]/(user authentication)/auth/reset-password/[[...token]]/action.ts b/app/(gcforms)/[locale]/(user authentication)/auth/reset-password/[[...token]]/action.ts index 63db09061a..2a7623c360 100644 --- a/app/(gcforms)/[locale]/(user authentication)/auth/reset-password/[[...token]]/action.ts +++ b/app/(gcforms)/[locale]/(user authentication)/auth/reset-password/[[...token]]/action.ts @@ -49,7 +49,6 @@ const validateInitialResetForm = async ( v.toLowerCase(), v.toTrimmed(), v.minLength(1, t("input-validation.required")), - v.email(t("input-validation.email")), v.custom((input) => isValidGovEmail(input), t("input-validation.validGovEmail")), ]), }); @@ -90,7 +89,6 @@ const validateQuestionChallengeForm = async ( v.toLowerCase(), v.toTrimmed(), v.minLength(1, t("input-validation.required")), - v.email(t("input-validation.email")), v.custom((input) => isValidGovEmail(input), t("input-validation.validGovEmail")), ]), }); @@ -113,7 +111,6 @@ const validatePasswordResetForm = async ( v.toLowerCase(), v.toTrimmed(), v.minLength(1, t("input-validation.required")), - v.email(t("input-validation.email")), v.custom((input) => isValidGovEmail(input), t("input-validation.validGovEmail")), ]), password: v.string([ diff --git a/cypress/e2e/login_page.cy.ts b/cypress/e2e/login_page.cy.ts index a9bd0e4a8c..22a1465b0a 100644 --- a/cypress/e2e/login_page.cy.ts +++ b/cypress/e2e/login_page.cy.ts @@ -37,7 +37,10 @@ describe("Login Page", () => { cy.get("button[type='submit']").should("be.visible"); cy.get("button[type='submit']").click(); cy.get("[id='errorMessageusername']").should("be.visible"); - cy.get("[id='errorMessageusername']").should("contain", "Enter a valid email address."); + cy.get("[id='errorMessageusername']").should( + "contain", + "Enter a valid government email address." + ); }); it("Displays no error message when submitting a valid email", () => { cy.typeInField("input[id='username']", "test@cds-snc.ca"); diff --git a/cypress/e2e/register_page.cy.ts b/cypress/e2e/register_page.cy.ts index e740fe946c..5d434e25ec 100644 --- a/cypress/e2e/register_page.cy.ts +++ b/cypress/e2e/register_page.cy.ts @@ -24,14 +24,17 @@ describe("Register Page", () => { it("Error on submitting a form with an invalid email", () => { cy.typeInField("input[id='username']", "myemail@email"); cy.get("[type='submit']").click(); - cy.get("[id='errorMessageusername']").should("contain", "Enter a valid email address."); + cy.get("[id='errorMessageusername']").should( + "contain", + "Enter a valid government email address." + ); }); it("Error on submitting a form with a non government email", () => { cy.typeInField("input[id='username']", "myemail@email.com"); cy.get("[type='submit']").click(); cy.get("[id='errorMessageusername']").should( "contain", - "This field must be a valid federal government email" + "Enter a valid government email address." ); }); it("No error on submitting a form with a valid government email", () => { diff --git a/lib/tests/validation/validation.test.js b/lib/tests/validation/validation.test.js index 51e1d9c7d7..4188895172 100644 --- a/lib/tests/validation/validation.test.js +++ b/lib/tests/validation/validation.test.js @@ -463,6 +463,7 @@ describe("Gov Email domain validator", () => { ["test@something.ca", false], ["test+example@cds-snc.ca", true], ["test.hi+example-1@cds-snc.ca", true], + ["test.with'apostrophe@cds-snc.ca", true], ])(`Should return true if email is valid (testing "%s")`, async (email, isValid) => { expect(isValidGovEmail(email)).toBe(isValid); });