From e52f51a76253894041c32f9bff4e33690b354176 Mon Sep 17 00:00:00 2001 From: Nikita Pekin Date: Thu, 9 Mar 2023 07:07:52 +0200 Subject: [PATCH] remove forgot password + reset password --- .../src/authentication/cognito.ts | 131 ------------ .../components/forgotPassword.tsx | 88 -------- .../src/authentication/components/login.tsx | 11 - .../components/resetPassword.tsx | 188 ------------------ .../src/authentication/providers/auth.tsx | 30 --- .../src/authentication/service.tsx | 22 +- .../src/authentication/src/components/app.tsx | 16 +- 7 files changed, 2 insertions(+), 484 deletions(-) delete mode 100644 app/ide-desktop/lib/dashboard/src/authentication/src/authentication/components/forgotPassword.tsx delete mode 100644 app/ide-desktop/lib/dashboard/src/authentication/src/authentication/components/resetPassword.tsx diff --git a/app/ide-desktop/lib/dashboard/src/authentication/src/authentication/cognito.ts b/app/ide-desktop/lib/dashboard/src/authentication/src/authentication/cognito.ts index 259829bb71d..876cbf428b2 100644 --- a/app/ide-desktop/lib/dashboard/src/authentication/src/authentication/cognito.ts +++ b/app/ide-desktop/lib/dashboard/src/authentication/src/authentication/cognito.ts @@ -28,11 +28,6 @@ const MESSAGES = { userNotConfirmed: 'User is not confirmed. Please check your email for a confirmation link.', incorrectUsernameOrPassword: 'Incorrect username or password.', }, - forgotPassword: { - userNotFound: 'User not found. Please register first.', - userNotConfirmed: - 'Cannot reset password for user with unverified email. Please verify your email first.', - }, } /** A list of known Amplify errors that we can match against prior to trying to convert to our @@ -43,11 +38,6 @@ const KNOWN_ERRORS = { code: 'NotAuthorizedException', message: 'User cannot be confirmed. Current status is CONFIRMED', }, - forgotPasswordUserNotConfirmed: { - code: 'InvalidParameterException', - message: - 'Cannot reset password for the user as there is no registered/verified email or phone_number', - }, } @@ -80,26 +70,6 @@ const intoAmplifyErrorOrThrow = (error: unknown): AmplifyError => { -// ================= -// === AuthError === -// ================= - -/** Object returned by the AWS Amplify library when an auth error occurs. */ -interface AuthError { - name: string - log: string -} - -/** Hints to TypeScript if we can safely cast an `unknown` error to an `AuthError`. */ -const isAuthError = (error: unknown): error is AuthError => { - if (error && typeof error === 'object') { - return 'name' in error && 'log' in error - } - return false -} - - - // =============== // === Cognito === // =============== @@ -153,32 +123,6 @@ export interface Cognito { username: string, password: string ) => Promise> - /** Sends a password reset email to the given email address. - * - * The user will be able to reset their password by following the link in the email, which takes - * them to the "reset password" page of the application. The verification code will be filled in - * automatically. - * - * @param email - Email address to send the password reset email to. - * @returns A promise that resolves to either success or known error. - * @throws An error if failed due to an unknown error. */ - forgotPassword: (username: string) => Promise> - /** Submits a new password for the given email address. - * - * The user will have received a verification code in an email, which they will have entered on - * the "reset password" page of the application. This function will submit the new password - * along with the verification code, changing the user's password. - * - * @param email - Email address to reset the password for. - * @param code - Verification code that was sent to the user's email address. - * @param password - New password to set. - * @returns A promise that resolves to either success or known error. - * @throws An error if failed due to an unknown error. */ - forgotPasswordSubmit: ( - username: string, - code: string, - newPassword: string - ) => Promise> /** Signs out the current user. * * @returns A promise that resolves if successful. */ @@ -233,8 +177,6 @@ export class CognitoImpl implements Cognito { signInWithGoogle = () => signInWithGoogle(this.customState()) signInWithGitHub = signInWithGitHub signInWithPassword = signInWithPassword - forgotPassword = forgotPassword - forgotPasswordSubmit = forgotPasswordSubmit signOut = () => signOut(this.logger) } @@ -486,79 +428,6 @@ const intoSignInWithPasswordErrorOrThrow = (error: AmplifyError): SignInWithPass -// ====================== -// === ForgotPassword === -// ====================== - -const forgotPassword = async (email: string) => - results.Result.wrapAsync(() => amplify.Auth.forgotPassword(email)) - // We don't care about the details in the success case, just that it happened. - .then(result => result.map(() => null)) - .then(result => result.mapErr(intoAmplifyErrorOrThrow)) - .then(result => result.mapErr(intoForgotPasswordErrorOrThrow)) - -type ForgotPasswordErrorKind = 'UserNotFound' | 'UserNotConfirmed' - -export interface ForgotPasswordError { - kind: ForgotPasswordErrorKind - message: string -} - -const intoForgotPasswordErrorOrThrow = (error: AmplifyError): ForgotPasswordError => { - if (error.code === 'UserNotFoundException') { - return { - kind: 'UserNotFound', - message: MESSAGES.forgotPassword.userNotFound, - } - } else if (error.code === KNOWN_ERRORS.forgotPasswordUserNotConfirmed.code) { - if (error.message === KNOWN_ERRORS.forgotPasswordUserNotConfirmed.message) { - return { - kind: 'UserNotConfirmed', - message: MESSAGES.forgotPassword.userNotConfirmed, - } - } - } - - throw error -} - - - -// ============================ -// === ForgotPasswordSubmit === -// ============================ - -const forgotPasswordSubmit = async (email: string, code: string, password: string) => - results.Result.wrapAsync(() => amplify.Auth.forgotPasswordSubmit(email, code, password)) - // We don't care about the details in the success case, just that it happened. - .then(result => result.map(() => null)) - .then(result => result.mapErr(intoForgotPasswordSubmitErrorOrThrow)) - -type ForgotPasswordSubmitErrorKind = 'AuthError' | 'AmplifyError' - -export interface ForgotPasswordSubmitError { - kind: ForgotPasswordSubmitErrorKind - message: string -} - -const intoForgotPasswordSubmitErrorOrThrow = (error: unknown): ForgotPasswordSubmitError => { - if (isAuthError(error)) { - return { - kind: 'AuthError', - message: error.log, - } - } else if (isAmplifyError(error)) { - return { - kind: 'AmplifyError', - message: error.message, - } - } - - throw error -} - - - // =============== // === SignOut === // =============== diff --git a/app/ide-desktop/lib/dashboard/src/authentication/src/authentication/components/forgotPassword.tsx b/app/ide-desktop/lib/dashboard/src/authentication/src/authentication/components/forgotPassword.tsx deleted file mode 100644 index ece11f20b1f..00000000000 --- a/app/ide-desktop/lib/dashboard/src/authentication/src/authentication/components/forgotPassword.tsx +++ /dev/null @@ -1,88 +0,0 @@ -/** @file Container responsible for rendering and interactions in first half of forgot password - * flow. */ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import * as React from "react"; -import * as router from "react-router-dom"; - -import * as auth from "../providers/auth"; -import withRouter from "../../navigation"; -import * as hooks from "../../hooks"; -import * as utils from "../../utils"; -import * as app from "../../components/app"; -import * as icons from "../../components/svg"; - - - -// =============================== -// === forgotPasswordContainer === -// =============================== - -const forgotPasswordContainer = () => { - const { forgotPassword } = auth.useAuth(); - - const { value: email, bind: bindEmail } = hooks.useInput(""); - - return ( -
-
-
- Forgot Your Password? -
-
-
await forgotPassword(email) - )} - > -
- -
-
- -
- - -
-
-
- -
-
-
-
- - - - - Go back to login - -
-
-
- ); -}; - -export default withRouter(forgotPasswordContainer); diff --git a/app/ide-desktop/lib/dashboard/src/authentication/src/authentication/components/login.tsx b/app/ide-desktop/lib/dashboard/src/authentication/src/authentication/components/login.tsx index ce45e9b786c..1281ac21053 100644 --- a/app/ide-desktop/lib/dashboard/src/authentication/src/authentication/components/login.tsx +++ b/app/ide-desktop/lib/dashboard/src/authentication/src/authentication/components/login.tsx @@ -126,17 +126,6 @@ const loginContainer = () => { -
-
- - Forgot Your Password? - -
-
-
-
- - -
- - - - - Go back to login - -
- - - ); -}; - -const parseUrlSearchParams = (search: string) => { - const query = new URLSearchParams(search); - const verificationCode = query.get( - RESET_PASSWORD_QUERY_PARAMS.verificationCode - ); - const email = query.get(RESET_PASSWORD_QUERY_PARAMS.email); - return { verificationCode, email }; -}; - -export default withRouter(resetPasswordContainer); diff --git a/app/ide-desktop/lib/dashboard/src/authentication/src/authentication/providers/auth.tsx b/app/ide-desktop/lib/dashboard/src/authentication/src/authentication/providers/auth.tsx index 80398d81ed8..7a8b28b4ce5 100644 --- a/app/ide-desktop/lib/dashboard/src/authentication/src/authentication/providers/auth.tsx +++ b/app/ide-desktop/lib/dashboard/src/authentication/src/authentication/providers/auth.tsx @@ -25,8 +25,6 @@ const MESSAGES = { confirmSignUpSuccess: "Your account has been confirmed! Please log in.", setUsernameSuccess: "Your username has been set!", signInWithPasswordSuccess: "Successfully logged in!", - forgotPasswordSuccess: "We have sent you an email with further instructions!", - resetPasswordSuccess: "Successfully reset password!", signOutSuccess: "Successfully logged out!", pleaseWait: "Please wait...", }; @@ -94,12 +92,6 @@ interface AuthContextType { signInWithGoogle: () => Promise; signInWithGitHub: () => Promise; signInWithPassword: (email: string, password: string) => Promise; - forgotPassword: (email: string) => Promise; - resetPassword: ( - email: string, - code: string, - password: string - ) => Promise; signOut: () => Promise; /** Session containing the currently authenticated user's authentication information. * @@ -281,26 +273,6 @@ export const AuthProvider = (props: AuthProviderProps) => { toast.error(result.val.message); }); - const forgotPassword = async (email: string) => - cognito.forgotPassword(email).then((result) => { - if (result.ok) { - toast.success(MESSAGES.forgotPasswordSuccess); - navigate(app.RESET_PASSWORD_PATH); - } else { - toast.error(result.val.message); - } - }); - - const resetPassword = async (email: string, code: string, password: string) => - cognito.forgotPasswordSubmit(email, code, password).then((result) => { - if (result.ok) { - toast.success(MESSAGES.resetPasswordSuccess); - navigate(app.LOGIN_PATH); - } else { - toast.error(result.val.message); - } - }); - const signOut = () => cognito .signOut() @@ -314,8 +286,6 @@ export const AuthProvider = (props: AuthProviderProps) => { signInWithGoogle: cognito.signInWithGoogle, signInWithGitHub: cognito.signInWithGitHub, signInWithPassword: withLoadingToast(signInWithPassword), - forgotPassword: withLoadingToast(forgotPassword), - resetPassword: withLoadingToast(resetPassword), signOut, session: userSession, }; diff --git a/app/ide-desktop/lib/dashboard/src/authentication/src/authentication/service.tsx b/app/ide-desktop/lib/dashboard/src/authentication/src/authentication/service.tsx index 65dce776ede..056d6bfa508 100644 --- a/app/ide-desktop/lib/dashboard/src/authentication/src/authentication/service.tsx +++ b/app/ide-desktop/lib/dashboard/src/authentication/src/authentication/service.tsx @@ -25,9 +25,6 @@ const SIGN_OUT_PATHNAME = "//auth"; /** Pathname of the {@link URL} for deep links to the registration confirmation page, after a * redirect from an account verification email. */ const CONFIRM_REGISTRATION_PATHNAME = "//auth/confirmation"; -/** Pathname of the {@link URL} for deep links to the login page, after a redirect from a reset - * password email. */ -const LOGIN_PATHNAME = "//auth/login"; const BASE_AMPLIFY_CONFIG: Partial = { region: authConfig.AWS_REGION, @@ -205,17 +202,10 @@ const setDeepLinkHandler = ( // Navigate to a relative URL to handle the confirmation link. const redirectUrl = `${app.CONFIRM_REGISTRATION_PATH}${parsedUrl.search}`; navigate(redirectUrl); - } else if (isSignOutRedirect(parsedUrl) || isLoginRedirect(parsedUrl)) { + } else if (isSignOutRedirect(parsedUrl)) { navigate(app.LOGIN_PATH); } else if (isSignInRedirect(parsedUrl)) { handleAuthResponse(url); - // If the user is being redirected from a password reset email, then we need to navigate to - // the password reset page, with the verification code and email passed in the URL so they - // can be filled in automatically. - } else if (isResetPasswordRedirect(parsedUrl)) { - // Navigate to a relative URL to handle the password reset. - const redirectUrl = `${app.RESET_PASSWORD_PATH}${parsedUrl.search}`; - navigate(redirectUrl); } else { logger.error(`${url} is an unrecognized deep link. Ignoring.`) } @@ -244,16 +234,6 @@ const isSignOutRedirect = (url: URL) => const isSignInRedirect = (url: URL) => url.pathname === SIGN_IN_PATHNAME && url.search !== ""; -/** If the user is being redirected after clicking the reset password confirmation link in their - * email, then the URL will be for the confirm password reset path. */ -const isResetPasswordRedirect = (url: URL) => - url.pathname === app.RESET_PASSWORD_PATH; - -/** If the user is being redirected after finishing the password reset flow, - * then the URL will be for the login page. */ -const isLoginRedirect = (url: URL) => - url.pathname === LOGIN_PATHNAME; - /** When the user is being redirected from a federated identity provider, then we need to pass the * URL to the Amplify library, which will parse the URL and complete the OAuth flow. */ const handleAuthResponse = (url: string) => { diff --git a/app/ide-desktop/lib/dashboard/src/authentication/src/components/app.tsx b/app/ide-desktop/lib/dashboard/src/authentication/src/components/app.tsx index fd9a63a0e19..344e26d6155 100644 --- a/app/ide-desktop/lib/dashboard/src/authentication/src/components/app.tsx +++ b/app/ide-desktop/lib/dashboard/src/authentication/src/components/app.tsx @@ -6,8 +6,6 @@ import * as router from "react-router-dom"; import * as authProvider from "../authentication/providers/auth"; import DashboardContainer from "../dashboard/components/dashboard"; -import ForgotPasswordContainer from "../authentication/components/forgotPassword"; -import ResetPasswordContainer from "../authentication/components/resetPassword"; import LoginContainer from "../authentication/components/login"; import RegistrationContainer from "../authentication/components/registration"; import ConfirmRegistrationContainer from "../authentication/components/confirmRegistration"; @@ -31,10 +29,6 @@ export const LOGIN_PATH = "/login"; export const REGISTRATION_PATH = "/registration"; /** Path to the confirm registration page. */ export const CONFIRM_REGISTRATION_PATH = "/confirmation"; -/** Path to the forgot password page. */ -export const FORGOT_PASSWORD_PATH = "/forgot-password"; -/** Path to the reset password page. */ -export const RESET_PASSWORD_PATH = "/password-reset"; /** Path to the set username page. */ export const SET_USERNAME_PATH = "/set-username"; @@ -84,7 +78,7 @@ const App = (props: AppProps) => { /** Router definition for the app. */ // eslint-disable-next-line @typescript-eslint/naming-convention const AppRouter = (props: AppProps) => { - const { logger, onAuthenticated, runningOnDesktop } = props; + const { logger, onAuthenticated } = props; const navigate = router.useNavigate(); const authConfig = { navigate, ...props }; const memoizedAuthService = React.useMemo( @@ -140,14 +134,6 @@ const AppRouter = (props: AppProps) => { path={CONFIRM_REGISTRATION_PATH} element={} /> - } - /> - } - />