Skip to content

Commit

Permalink
Jamakase/fix password invalid text (#6939)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamakase authored Oct 26, 2021
1 parent 22f8c39 commit 6fc9418
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 62 deletions.
7 changes: 2 additions & 5 deletions airbyte-webapp/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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."
}
84 changes: 33 additions & 51 deletions airbyte-webapp/src/packages/cloud/lib/auth/GoogleAuthService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
reauthenticateWithCredential,
updatePassword,
updateEmail,
AuthErrorCodes,
} from "firebase/auth";

import { FieldError } from "packages/cloud/lib/errors/FieldError";
Expand All @@ -21,7 +22,7 @@ import { Provider } from "config";
interface AuthService {
login(email: string, password: string): Promise<UserCredential>;

signOut(): Promise<any>;
signOut(): Promise<void>;

signUp(email: string, password: string): Promise<UserCredential>;

Expand Down Expand Up @@ -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);
}

Expand All @@ -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;
Expand All @@ -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<void> {
Expand All @@ -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<void> {
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<void> {
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<void> {
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<void> {
Expand Down
7 changes: 6 additions & 1 deletion airbyte-webapp/src/packages/cloud/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
5 changes: 1 addition & 4 deletions airbyte-webapp/src/packages/cloud/services/auth/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
export enum ErrorCodes {
DuplicateEmail = "email.duplicate",
InvalidEmail = "email.invalid",
WeakPassword = "password.weak",

Duplicate = "duplicate",
Invalid = "invalid",
Validation = "validation",
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit 6fc9418

Please sign in to comment.