From 103d441f081328bcbe4b4e3e8e505998fdc88e52 Mon Sep 17 00:00:00 2001 From: Hailey Date: Tue, 2 Apr 2024 15:49:39 -0700 Subject: [PATCH] remove some more unnecessary stuff --- src/screens/Login/ForgotPasswordForm.tsx | 184 --------------------- src/screens/Login/LoginForm.tsx | 46 ++---- src/screens/Login/PasswordUpdatedForm.tsx | 50 ------ src/screens/Login/SetNewPasswordForm.tsx | 192 ---------------------- src/screens/Login/index.tsx | 55 +------ 5 files changed, 15 insertions(+), 512 deletions(-) delete mode 100644 src/screens/Login/ForgotPasswordForm.tsx delete mode 100644 src/screens/Login/PasswordUpdatedForm.tsx delete mode 100644 src/screens/Login/SetNewPasswordForm.tsx diff --git a/src/screens/Login/ForgotPasswordForm.tsx b/src/screens/Login/ForgotPasswordForm.tsx deleted file mode 100644 index 580452e75b..0000000000 --- a/src/screens/Login/ForgotPasswordForm.tsx +++ /dev/null @@ -1,184 +0,0 @@ -import React, {useEffect, useState} from 'react' -import {ActivityIndicator, Keyboard, View} from 'react-native' -import {ComAtprotoServerDescribeServer} from '@atproto/api' -import {BskyAgent} from '@atproto/api' -import {msg, Trans} from '@lingui/macro' -import {useLingui} from '@lingui/react' -import * as EmailValidator from 'email-validator' - -import {useAnalytics} from '#/lib/analytics/analytics' -import {isNetworkError} from '#/lib/strings/errors' -import {cleanError} from '#/lib/strings/errors' -import {logger} from '#/logger' -import {atoms as a, useTheme} from '#/alf' -import {Button, ButtonText} from '#/components/Button' -import {FormError} from '#/components/forms/FormError' -import {HostingProvider} from '#/components/forms/HostingProvider' -import * as TextField from '#/components/forms/TextField' -import {At_Stroke2_Corner0_Rounded as At} from '#/components/icons/At' -import {Text} from '#/components/Typography' -import {FormContainer} from './FormContainer' - -type ServiceDescription = ComAtprotoServerDescribeServer.OutputSchema - -export const ForgotPasswordForm = ({ - error, - serviceUrl, - serviceDescription, - setError, - setServiceUrl, - onPressBack, - onEmailSent, -}: { - error: string - serviceUrl: string - serviceDescription: ServiceDescription | undefined - setError: (v: string) => void - setServiceUrl: (v: string) => void - onPressBack: () => void - onEmailSent: () => void -}) => { - const t = useTheme() - const [isProcessing, setIsProcessing] = useState(false) - const [email, setEmail] = useState('') - const {screen} = useAnalytics() - const {_} = useLingui() - - useEffect(() => { - screen('Signin:ForgotPassword') - }, [screen]) - - const onPressSelectService = React.useCallback(() => { - Keyboard.dismiss() - }, []) - - const onPressNext = async () => { - if (!EmailValidator.validate(email)) { - return setError(_(msg`Your email appears to be invalid.`)) - } - - setError('') - setIsProcessing(true) - - try { - const agent = new BskyAgent({service: serviceUrl}) - await agent.com.atproto.server.requestPasswordReset({email}) - onEmailSent() - } catch (e: any) { - const errMsg = e.toString() - logger.warn('Failed to request password reset', {error: e}) - setIsProcessing(false) - if (isNetworkError(e)) { - setError( - _( - msg`Unable to contact your service. Please check your Internet connection.`, - ), - ) - } else { - setError(cleanError(errMsg)) - } - } - } - - return ( - Reset password}> - - - Hosting provider - - - - - - Email address - - - - - - - - - - Enter the email you used to create your account. We'll send you a - "reset code" so you can set a new password. - - - - - - - - - {!serviceDescription || isProcessing ? ( - - ) : ( - - )} - {!serviceDescription || isProcessing ? ( - - Processing... - - ) : undefined} - - - - - - ) -} diff --git a/src/screens/Login/LoginForm.tsx b/src/screens/Login/LoginForm.tsx index e090e080c3..919591eb5e 100644 --- a/src/screens/Login/LoginForm.tsx +++ b/src/screens/Login/LoginForm.tsx @@ -1,31 +1,17 @@ -import React, {useRef, useState} from 'react' -import { - ActivityIndicator, - Keyboard, - LayoutAnimation, - TextInput, - View, -} from 'react-native' +import React from 'react' +import {Keyboard, View} from 'react-native' import * as Browser from 'expo-web-browser' import {ComAtprotoServerDescribeServer} from '@atproto/api' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import {useAnalytics} from '#/lib/analytics/analytics' -import {isNetworkError} from '#/lib/strings/errors' -import {cleanError} from '#/lib/strings/errors' -import {createFullHandle} from '#/lib/strings/handles' -import {logger} from '#/logger' -import {useSessionApi} from '#/state/session' -import {atoms as a, useTheme} from '#/alf' -import {Button, ButtonIcon, ButtonText} from '#/components/Button' +import {isAndroid} from 'platform/detection' +import {atoms as a} from '#/alf' +import {Button, ButtonText} from '#/components/Button' import {FormError} from '#/components/forms/FormError' import {HostingProvider} from '#/components/forms/HostingProvider' import * as TextField from '#/components/forms/TextField' -import {At_Stroke2_Corner0_Rounded as At} from '#/components/icons/At' -import {Lock_Stroke2_Corner0_Rounded as Lock} from '#/components/icons/Lock' -import {Loader} from '#/components/Loader' -import {Text} from '#/components/Typography' import {FormContainer} from './FormContainer' type ServiceDescription = ComAtprotoServerDescribeServer.OutputSchema @@ -34,17 +20,14 @@ export const LoginForm = ({ error, serviceUrl, serviceDescription, - initialHandle, setError, setServiceUrl, onPressRetryConnect, onPressBack, - onPressForgotPassword, }: { error: string serviceUrl: string serviceDescription: ServiceDescription | undefined - initialHandle: string setError: (v: string) => void setServiceUrl: (v: string) => void onPressRetryConnect: () => void @@ -52,15 +35,13 @@ export const LoginForm = ({ onPressForgotPassword: () => void }) => { const {track} = useAnalytics() - const t = useTheme() - const [isProcessing, setIsProcessing] = useState(false) - const passwordInputRef = useRef(null) const {_} = useLingui() - const {login} = useSessionApi() // This improves speed at which the browser presents itself on Android React.useEffect(() => { - Browser.warmUpAsync() + if (isAndroid) { + Browser.warmUpAsync() + } }, []) const onPressSelectService = React.useCallback(() => { @@ -73,9 +54,7 @@ export const LoginForm = ({ 'https://bsky.app/login', // Replace this with the PDS auth url 'bsky://login', // Replace this as well with the appropriate link { - // Similar to how Google auth works. Sessions will be remembered so that we can - // usually proceed without needing credentials - preferEphemeralSession: true, + windowFeatures: {}, }, ) @@ -86,6 +65,8 @@ export const LoginForm = ({ // Handle session storage here } + console.log(serviceDescription) + return ( Sign in}> @@ -115,9 +96,10 @@ export const LoginForm = ({ variant="solid" color="primary" size="medium" - onPress={onPressBack}> + onPress={onPressNext} + disabled={!serviceDescription}> - Login + Sign In diff --git a/src/screens/Login/PasswordUpdatedForm.tsx b/src/screens/Login/PasswordUpdatedForm.tsx deleted file mode 100644 index 5407f3f1e3..0000000000 --- a/src/screens/Login/PasswordUpdatedForm.tsx +++ /dev/null @@ -1,50 +0,0 @@ -import React, {useEffect} from 'react' -import {View} from 'react-native' -import {msg, Trans} from '@lingui/macro' -import {useLingui} from '@lingui/react' - -import {useAnalytics} from '#/lib/analytics/analytics' -import {atoms as a, useBreakpoints} from '#/alf' -import {Button, ButtonText} from '#/components/Button' -import {Text} from '#/components/Typography' -import {FormContainer} from './FormContainer' - -export const PasswordUpdatedForm = ({ - onPressNext, -}: { - onPressNext: () => void -}) => { - const {screen} = useAnalytics() - const {_} = useLingui() - const {gtMobile} = useBreakpoints() - - useEffect(() => { - screen('Signin:PasswordUpdatedForm') - }, [screen]) - - return ( - - - Password updated! - - - You can now sign in with your new password. - - - - - - ) -} diff --git a/src/screens/Login/SetNewPasswordForm.tsx b/src/screens/Login/SetNewPasswordForm.tsx deleted file mode 100644 index e7b4886550..0000000000 --- a/src/screens/Login/SetNewPasswordForm.tsx +++ /dev/null @@ -1,192 +0,0 @@ -import React, {useEffect, useState} from 'react' -import {ActivityIndicator, View} from 'react-native' -import {BskyAgent} from '@atproto/api' -import {msg, Trans} from '@lingui/macro' -import {useLingui} from '@lingui/react' - -import {useAnalytics} from '#/lib/analytics/analytics' -import {isNetworkError} from '#/lib/strings/errors' -import {cleanError} from '#/lib/strings/errors' -import {checkAndFormatResetCode} from '#/lib/strings/password' -import {logger} from '#/logger' -import {atoms as a, useTheme} from '#/alf' -import {Button, ButtonText} from '#/components/Button' -import {FormError} from '#/components/forms/FormError' -import * as TextField from '#/components/forms/TextField' -import {Lock_Stroke2_Corner0_Rounded as Lock} from '#/components/icons/Lock' -import {Ticket_Stroke2_Corner0_Rounded as Ticket} from '#/components/icons/Ticket' -import {Text} from '#/components/Typography' -import {FormContainer} from './FormContainer' - -export const SetNewPasswordForm = ({ - error, - serviceUrl, - setError, - onPressBack, - onPasswordSet, -}: { - error: string - serviceUrl: string - setError: (v: string) => void - onPressBack: () => void - onPasswordSet: () => void -}) => { - const {screen} = useAnalytics() - const {_} = useLingui() - const t = useTheme() - - useEffect(() => { - screen('Signin:SetNewPasswordForm') - }, [screen]) - - const [isProcessing, setIsProcessing] = useState(false) - const [resetCode, setResetCode] = useState('') - const [password, setPassword] = useState('') - - const onPressNext = async () => { - // Check that the code is correct. We do this again just incase the user enters the code after their pw and we - // don't get to call onBlur first - const formattedCode = checkAndFormatResetCode(resetCode) - // TODO Better password strength check - if (!formattedCode || !password) { - setError( - _( - msg`You have entered an invalid code. It should look like XXXXX-XXXXX.`, - ), - ) - return - } - - setError('') - setIsProcessing(true) - - try { - const agent = new BskyAgent({service: serviceUrl}) - await agent.com.atproto.server.resetPassword({ - token: formattedCode, - password, - }) - onPasswordSet() - } catch (e: any) { - const errMsg = e.toString() - logger.warn('Failed to set new password', {error: e}) - setIsProcessing(false) - if (isNetworkError(e)) { - setError( - _( - msg`Unable to contact your service. Please check your Internet connection.`, - ), - ) - } else { - setError(cleanError(errMsg)) - } - } - } - - const onBlur = () => { - const formattedCode = checkAndFormatResetCode(resetCode) - if (!formattedCode) { - setError( - _( - msg`You have entered an invalid code. It should look like XXXXX-XXXXX.`, - ), - ) - return - } - setResetCode(formattedCode) - } - - return ( - Set new password}> - - - You will receive an email with a "reset code." Enter that code here, - then enter your new password. - - - - - Reset code - - - setError('')} - onBlur={onBlur} - editable={!isProcessing} - accessibilityHint={_( - msg`Input code sent to your email for password reset`, - )} - /> - - - - - New password - - - - - - - - - - - - {isProcessing ? ( - - ) : ( - - )} - {isProcessing ? ( - - Updating... - - ) : undefined} - - - ) -} diff --git a/src/screens/Login/index.tsx b/src/screens/Login/index.tsx index 1fce63d298..42b355a730 100644 --- a/src/screens/Login/index.tsx +++ b/src/screens/Login/index.tsx @@ -4,17 +4,13 @@ import {LayoutAnimationConfig} from 'react-native-reanimated' import {msg} from '@lingui/macro' import {useLingui} from '@lingui/react' -import {useAnalytics} from '#/lib/analytics/analytics' import {DEFAULT_SERVICE} from '#/lib/constants' import {logger} from '#/logger' import {useServiceQuery} from '#/state/queries/service' import {SessionAccount, useSession} from '#/state/session' import {useLoggedOutView} from '#/state/shell/logged-out' import {LoggedOutLayout} from '#/view/com/util/layouts/LoggedOutLayout' -import {ForgotPasswordForm} from '#/screens/Login/ForgotPasswordForm' import {LoginForm} from '#/screens/Login/LoginForm' -import {PasswordUpdatedForm} from '#/screens/Login/PasswordUpdatedForm' -import {SetNewPasswordForm} from '#/screens/Login/SetNewPasswordForm' import {atoms as a} from '#/alf' import {ChooseAccountForm} from './ChooseAccountForm' import {ScreenTransition} from './ScreenTransition' @@ -22,16 +18,12 @@ import {ScreenTransition} from './ScreenTransition' enum Forms { Login, ChooseAccount, - ForgotPassword, - SetNewPassword, - PasswordUpdated, } export const Login = ({onPressBack}: {onPressBack: () => void}) => { const {_} = useLingui() const {accounts} = useSession() - const {track} = useAnalytics() const {requestedAccountSwitchTo} = useLoggedOutView() const requestedAccount = accounts.find( acc => acc.did === requestedAccountSwitchTo, @@ -41,9 +33,6 @@ export const Login = ({onPressBack}: {onPressBack: () => void}) => { const [serviceUrl, setServiceUrl] = React.useState( requestedAccount?.service || DEFAULT_SERVICE, ) - const [initialHandle, setInitialHandle] = React.useState( - requestedAccount?.handle || '', - ) const [currentForm, setCurrentForm] = React.useState( requestedAccount ? Forms.Login @@ -62,7 +51,7 @@ export const Login = ({onPressBack}: {onPressBack: () => void}) => { if (account?.service) { setServiceUrl(account.service) } - setInitialHandle(account?.handle || '') + // TODO set the service URL. We really need to fix this though in general setCurrentForm(Forms.Login) } @@ -86,11 +75,6 @@ export const Login = ({onPressBack}: {onPressBack: () => void}) => { } }, [serviceError, serviceUrl, _]) - const onPressForgotPassword = () => { - track('Signin:PressedForgotPassword') - setCurrentForm(Forms.ForgotPassword) - } - let content = null let title = '' let description = '' @@ -104,13 +88,11 @@ export const Login = ({onPressBack}: {onPressBack: () => void}) => { error={error} serviceUrl={serviceUrl} serviceDescription={serviceDescription} - initialHandle={initialHandle} setError={setError} setServiceUrl={setServiceUrl} onPressBack={() => accounts.length ? gotoForm(Forms.ChooseAccount) : onPressBack() } - onPressForgotPassword={onPressForgotPassword} onPressRetryConnect={refetchService} /> ) @@ -125,41 +107,6 @@ export const Login = ({onPressBack}: {onPressBack: () => void}) => { /> ) break - case Forms.ForgotPassword: - title = _(msg`Forgot Password`) - description = _(msg`Let's get your password reset!`) - content = ( - gotoForm(Forms.Login)} - onEmailSent={() => gotoForm(Forms.SetNewPassword)} - /> - ) - break - case Forms.SetNewPassword: - title = _(msg`Forgot Password`) - description = _(msg`Let's get your password reset!`) - content = ( - gotoForm(Forms.ForgotPassword)} - onPasswordSet={() => gotoForm(Forms.PasswordUpdated)} - /> - ) - break - case Forms.PasswordUpdated: - title = _(msg`Password updated`) - description = _(msg`You can now sign in with your new password.`) - content = ( - gotoForm(Forms.Login)} /> - ) - break } return (