From 6fc9418fcf3d0eb408f587ab607042a01400ac4d Mon Sep 17 00:00:00 2001 From: Artem Astapenko <3767150+Jamakase@users.noreply.github.com> Date: Tue, 26 Oct 2021 21:09:57 +0300 Subject: [PATCH] Jamakase/fix password invalid text (#6939) --- airbyte-webapp/src/locales/en.json | 7 +- .../cloud/lib/auth/GoogleAuthService.ts | 84 ++++++++----------- .../src/packages/cloud/locales/en.json | 7 +- .../src/packages/cloud/services/auth/types.ts | 5 +- .../views/auth/SignupPage/SignupPage.tsx | 5 +- 5 files changed, 46 insertions(+), 62 deletions(-) diff --git a/airbyte-webapp/src/locales/en.json b/airbyte-webapp/src/locales/en.json index f9d285a54b4e..ff4030743e34 100644 --- a/airbyte-webapp/src/locales/en.json +++ b/airbyte-webapp/src/locales/en.json @@ -17,7 +17,7 @@ "form.yourEmail": "Your email", "form.email.placeholder": "you@company.com", "form.email.error": "This email address doesn’t seem correct.", - "form.empty.error": "Empty field", + "form.empty.error": "Field is required", "form.selectConnector": "Select a connector", "form.searchName": "search by name...", "form.noResult": "No result", @@ -414,8 +414,5 @@ "credits.totalUsage": "Total usage", "demo.message.title": "This Airbyte demo is read-only", - "demo.message.body": "You cannot add or edit any connectors. You will see error messages on purpose if you try to do so.", - - "email.duplicate": "Email already exists", - "password.invalid": "Password too weak" + "demo.message.body": "You cannot add or edit any connectors. You will see error messages on purpose if you try to do so." } diff --git a/airbyte-webapp/src/packages/cloud/lib/auth/GoogleAuthService.ts b/airbyte-webapp/src/packages/cloud/lib/auth/GoogleAuthService.ts index 186a8e6698c8..b5e2a6ab19c6 100644 --- a/airbyte-webapp/src/packages/cloud/lib/auth/GoogleAuthService.ts +++ b/airbyte-webapp/src/packages/cloud/lib/auth/GoogleAuthService.ts @@ -12,6 +12,7 @@ import { reauthenticateWithCredential, updatePassword, updateEmail, + AuthErrorCodes, } from "firebase/auth"; import { FieldError } from "packages/cloud/lib/errors/FieldError"; @@ -21,7 +22,7 @@ import { Provider } from "config"; interface AuthService { login(email: string, password: string): Promise; - signOut(): Promise; + signOut(): Promise; signUp(email: string, password: string): Promise; @@ -56,13 +57,13 @@ export class GoogleAuthService implements AuthService { return signInWithEmailAndPassword(this.auth, email, password).catch( (err) => { switch (err.code) { - case "auth/invalid-email": + case AuthErrorCodes.INVALID_EMAIL: throw new FieldError("email", ErrorCodes.Invalid); - case "auth/user-disabled": + case AuthErrorCodes.USER_CANCELLED: throw new FieldError("email", "disabled"); - case "auth/user-not-found": + case AuthErrorCodes.USER_DELETED: throw new FieldError("email", "notfound"); - case "auth/wrong-password": + case AuthErrorCodes.INVALID_PASSWORD: throw new FieldError("password", ErrorCodes.Invalid); } @@ -75,12 +76,12 @@ export class GoogleAuthService implements AuthService { return createUserWithEmailAndPassword(this.auth, email, password).catch( (err) => { switch (err.code) { - case "auth/email-already-in-use": + case AuthErrorCodes.EMAIL_EXISTS: throw new FieldError("email", ErrorCodes.Duplicate); - case "auth/invalid-email": + case AuthErrorCodes.INVALID_EMAIL: throw new FieldError("email", ErrorCodes.Invalid); - case "auth/weak-password": - throw new FieldError("password", ErrorCodes.Invalid); + case AuthErrorCodes.WEAK_PASSWORD: + throw new FieldError("password", ErrorCodes.Validation); } throw err; @@ -103,9 +104,7 @@ export class GoogleAuthService implements AuthService { if (this.auth.currentUser === null) { throw new Error("You must log in first to update password!"); } - return updatePassword(this.auth.currentUser, newPassword).catch((err) => { - throw err; - }); + return updatePassword(this.auth.currentUser, newPassword); } async updateEmail(email: string, password: string): Promise { @@ -114,55 +113,38 @@ export class GoogleAuthService implements AuthService { if (user) { await this.reauthenticate(email, password); - return updateEmail(user, email); + try { + await updateEmail(user, email); + } catch (e) { + switch (e.code) { + case "auth/invalid-email": + throw new FieldError("email", ErrorCodes.Invalid); + case "auth/email-already-in-use": + throw new FieldError("email", ErrorCodes.Duplicate); + case "auth/requires-recent-login": + throw new Error("auth/requires-recent-login"); + } + } } - - return Promise.resolve(); } async resetPassword(email: string): Promise { - return sendPasswordResetEmail(this.auth, email).catch((err) => { - // switch (err.code) { - // case "auth/email-already-in-use": - // throw new FieldError("email", ErrorCodes.Duplicate); - // case "auth/invalid-email": - // throw new FieldError("email", ErrorCodes.Invalid); - // case "auth/weak-password": - // throw new FieldError("password", ErrorCodes.Invalid); - // } - - throw err; - }); + return sendPasswordResetEmail(this.auth, email); } async finishResetPassword(code: string, newPassword: string): Promise { - return confirmPasswordReset(this.auth, code, newPassword).catch((err) => { - // switch (err.code) { - // case "auth/email-already-in-use": - // throw new FieldError("email", ErrorCodes.Duplicate); - // case "auth/invalid-email": - // throw new FieldError("email", ErrorCodes.Invalid); - // case "auth/weak-password": - // throw new FieldError("password", ErrorCodes.Invalid); - // } - - throw err; - }); + return confirmPasswordReset(this.auth, code, newPassword); } async sendEmailVerifiedLink(): Promise { - return sendEmailVerification(this.getCurrentUser()!).catch((err) => { - // switch (err.code) { - // case "auth/email-already-in-use": - // throw new FieldError("email", ErrorCodes.Duplicate); - // case "auth/invalid-email": - // throw new FieldError("email", ErrorCodes.Invalid); - // case "auth/weak-password": - // throw new FieldError("password", ErrorCodes.Invalid); - // } - - throw err; - }); + const currentUser = this.getCurrentUser(); + + if (!currentUser) { + console.error("sendEmailVerifiedLink should be used within auth flow"); + throw new Error("user is not authorised"); + } + + return sendEmailVerification(currentUser); } async confirmEmailVerify(code: string): Promise { diff --git a/airbyte-webapp/src/packages/cloud/locales/en.json b/airbyte-webapp/src/packages/cloud/locales/en.json index f85e5040faf0..0b62925f24e2 100644 --- a/airbyte-webapp/src/packages/cloud/locales/en.json +++ b/airbyte-webapp/src/packages/cloud/locales/en.json @@ -97,5 +97,10 @@ "firebase.auth.error.invalidPassword": "Incorrect password", "firebase.auth.error.networkRequestFailed": "There appears to be a network issue. Please try again later.", "firebase.auth.error.tooManyRequests": "Too many retries. Please wait 10 minutes before trying again.", - "firebase.auth.error.default": "Confirmation email cannot be sent. Please try again later." + "firebase.auth.error.default": "Confirmation email cannot be sent. Please try again later.", + + "signup.password.minLength": "Password should be at least 6 characters", + "email.duplicate": "Email already exists", + "password.validation": "Your password is too weak", + "password.invalid": "Invalid password" } diff --git a/airbyte-webapp/src/packages/cloud/services/auth/types.ts b/airbyte-webapp/src/packages/cloud/services/auth/types.ts index 8d7e43caa98b..135976dbe6f1 100644 --- a/airbyte-webapp/src/packages/cloud/services/auth/types.ts +++ b/airbyte-webapp/src/packages/cloud/services/auth/types.ts @@ -1,8 +1,5 @@ export enum ErrorCodes { - DuplicateEmail = "email.duplicate", - InvalidEmail = "email.invalid", - WeakPassword = "password.weak", - Duplicate = "duplicate", Invalid = "invalid", + Validation = "validation", } diff --git a/airbyte-webapp/src/packages/cloud/views/auth/SignupPage/SignupPage.tsx b/airbyte-webapp/src/packages/cloud/views/auth/SignupPage/SignupPage.tsx index f63e5d713e0d..50d2d18145e2 100644 --- a/airbyte-webapp/src/packages/cloud/views/auth/SignupPage/SignupPage.tsx +++ b/airbyte-webapp/src/packages/cloud/views/auth/SignupPage/SignupPage.tsx @@ -33,7 +33,10 @@ const MarginBlock = styled.div` const SignupPageValidationSchema = yup.object().shape({ email: yup.string().email("form.email.error").required("form.empty.error"), - password: yup.string().required("form.empty.error"), + password: yup + .string() + .min(6, "signup.password.minLength") + .required("form.empty.error"), name: yup.string().required("form.empty.error"), company: yup.string().required("form.empty.error"), security: yup.boolean().oneOf([true], "form.empty.error"),