Skip to content

Commit

Permalink
feat: add button for 2fa submit (#14961)
Browse files Browse the repository at this point in the history
  • Loading branch information
tlebon committed Apr 3, 2023
1 parent 46a2609 commit 92fdea7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@
"login.subhead": "Enter your email address or username.",
"login.twoFactorLoginSubHead": "Please check your email {email} for the verification code and enter it below.",
"login.twoFactorLoginTitle": "Verify your account",
"login.submitTwoFactorButton": "Submit",
"mediaBtnPause": "Pause",
"mediaBtnPlay": "Play",
"messageCouldNotBeSent": "Message could not be sent due to connectivity issues.",
Expand Down
23 changes: 21 additions & 2 deletions src/script/auth/page/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {AnyAction, Dispatch} from 'redux';
import {Runtime, UrlUtil} from '@wireapp/commons';
import {
ArrowIcon,
Button,
Checkbox,
CheckboxLabel,
CodeInput,
Expand All @@ -39,6 +40,7 @@ import {
Columns,
Container,
ContainerXS,
FlexBox,
Form,
H1,
H2,
Expand Down Expand Up @@ -103,6 +105,8 @@ const LoginComponent = ({

const [twoFactorSubmitError, setTwoFactorSubmitError] = useState<string | Error>('');
const [twoFactorLoginData, setTwoFactorLoginData] = useState<LoginData>();
const [verificationCode, setVerificationCode] = useState('');
const [twoFactorSubmitFailedOnce, setTwoFactorSubmitFailedOnce] = useState(false);

const isOauth = UrlUtil.hasURLParameter(QUERY_KEY.SCOPE);

Expand Down Expand Up @@ -244,6 +248,7 @@ const LoginComponent = ({

case BackendError.LABEL.CODE_AUTHENTICATION_FAILED: {
setTwoFactorSubmitError(error);
setTwoFactorSubmitFailedOnce(true);
break;
}
case BackendError.LABEL.INVALID_CREDENTIALS:
Expand Down Expand Up @@ -281,8 +286,12 @@ const LoginComponent = ({
};

const submitTwoFactorLogin = (code?: string) => {
setVerificationCode(code ?? '');
setTwoFactorSubmitError('');
handleSubmit({...twoFactorLoginData, verificationCode: code}, []);
// Do not auto submit if already failed once
if (!twoFactorSubmitFailedOnce) {
handleSubmit({...twoFactorLoginData, verificationCode: code}, []);
}
};

const storeEntropy = async (entropyData: Uint8Array) => {
Expand Down Expand Up @@ -333,10 +342,10 @@ const LoginComponent = ({
</Text>
<Label markInvalid={!!twoFactorSubmitError}>
<CodeInput
disabled={isFetching}
style={{marginTop: 60}}
onCodeComplete={submitTwoFactorLogin}
data-uie-name="enter-code"
markInvalid={!!twoFactorSubmitError}
/>
</Label>
<div style={{display: 'flex', justifyContent: 'center', marginTop: 10}}>
Expand All @@ -351,6 +360,16 @@ const LoginComponent = ({
</TextLink>
)}
</div>
<FlexBox justify="center">
<Button
disabled={!!twoFactorSubmitError || isFetching}
type="submit"
css={{marginTop: 65}}
onClick={() => handleSubmit({...twoFactorLoginData, verificationCode}, [])}
>
{_({id: 'login.submitTwoFactorButton'})}
</Button>
</FlexBox>
</div>
) : (
<>
Expand Down
4 changes: 4 additions & 0 deletions src/script/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,10 @@ export const loginStrings = defineMessages({
defaultMessage: 'Verify your account',
id: 'login.twoFactorLoginTitle',
},
submitTwoFactorButton: {
defaultMessage: 'Submit',
id: 'login.submitTwoFactorButton',
},
});

export const ssoLoginStrings = defineMessages({
Expand Down

0 comments on commit 92fdea7

Please sign in to comment.