Skip to content

Commit db4afa8

Browse files
committed
Add ability to send totp
1 parent 0d43c23 commit db4afa8

8 files changed

Lines changed: 33 additions & 24 deletions

File tree

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,6 @@
6565
"typescript": "^5.2.2"
6666
},
6767
"dependencies": {
68-
"@authorizerdev/authorizer-js": "^1.2.15"
68+
"@authorizerdev/authorizer-js": "^1.2.17"
6969
}
7070
}

src/components/AuthorizerBasicAuthLogin.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import { OtpDataType, TotpDataType } from '../types';
1212
import { AuthorizerTOTPScanner } from './AuthorizerTOTPScanner';
1313

1414
const initOtpData: OtpDataType = {
15-
isScreenVisible: false,
15+
is_screen_visible: false,
1616
email: '',
1717
phone_number: '',
1818
};
1919

2020
const initTotpData: TotpDataType = {
21-
isScreenVisible: false,
21+
is_screen_visible: false,
2222
email: '',
2323
phone_number: '',
2424
authenticator_scanner_image: '',
@@ -85,7 +85,7 @@ export const AuthorizerBasicAuthLogin: FC<{
8585
res.authenticator_recovery_codes
8686
) {
8787
setTotpData({
88-
isScreenVisible: true,
88+
is_screen_visible: true,
8989
email: data.email || ``,
9090
phone_number: data.phone_number || ``,
9191
authenticator_scanner_image: res.authenticator_scanner_image,
@@ -101,9 +101,10 @@ export const AuthorizerBasicAuthLogin: FC<{
101101
res?.should_show_totp_screen)
102102
) {
103103
setOtpData({
104-
isScreenVisible: true,
104+
is_screen_visible: true,
105105
email: data.email || ``,
106106
phone_number: data.phone_number || ``,
107+
is_totp: res?.should_show_totp_screen || false,
107108
});
108109
return;
109110
}
@@ -163,7 +164,7 @@ export const AuthorizerBasicAuthLogin: FC<{
163164
}
164165
}, [formData.password]);
165166

166-
if (totpData.isScreenVisible) {
167+
if (totpData.is_screen_visible) {
167168
return (
168169
<AuthorizerTOTPScanner
169170
{...{
@@ -181,14 +182,15 @@ export const AuthorizerBasicAuthLogin: FC<{
181182
);
182183
}
183184

184-
if (otpData.isScreenVisible) {
185+
if (otpData.is_screen_visible) {
185186
return (
186187
<AuthorizerVerifyOtp
187188
{...{
188189
setView,
189190
onLogin,
190191
email: otpData.email || ``,
191192
phone_number: otpData.phone_number || ``,
193+
is_totp: otpData.is_totp || false,
192194
}}
193195
urlProps={urlProps}
194196
/>
@@ -207,7 +209,7 @@ export const AuthorizerBasicAuthLogin: FC<{
207209
className={styles['form-input-label']}
208210
htmlFor="authorizer-login-email"
209211
>
210-
<span>* </span>Email
212+
<span>* </span>Email / Phone Number
211213
</label>
212214
<input
213215
name="email_or_phone_number"

src/components/AuthorizerTOTPScanner.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { FC, useState } from 'react';
2-
import { StyledButton } from '../styledComponents';
2+
import { StyledButton, StyledFlex, StyledSeparator } from '../styledComponents';
33
import { ButtonAppearance, Views } from '../constants';
44
import { AuthorizerVerifyOtp } from './AuthorizerVerifyOtp';
55

@@ -46,17 +46,20 @@ export const AuthorizerTOTPScanner: FC<{
4646
<p style={{ margin: '10px 0px', fontWeight: 'bold' }}>
4747
Scan the QR code or enter the secret key into your authenticator app.
4848
</p>
49-
<img
50-
src={`data:image/jpeg;base64,${authenticator_scanner_image}`}
51-
alt="scanner"
52-
/>
49+
<StyledFlex justifyContent="center">
50+
<img
51+
src={`data:image/jpeg;base64,${authenticator_scanner_image}`}
52+
alt="scanner"
53+
/>
54+
</StyledFlex>
5355
<p style={{ margin: '10px 0px' }}>
5456
If you are unable to scan the QR code, please enter the secret key
5557
manually.
5658
</p>
5759
<p style={{ margin: '10px 0px', fontWeight: 'bold' }}>
5860
{authenticator_secret}
5961
</p>
62+
<StyledSeparator />
6063
<p style={{ margin: '10px 0px' }}>
6164
If you lose access to your authenticator app, you can use the recovery
6265
codes below to regain access to your account. Please save these codes

src/components/AuthorizerVerifyOtp.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ export const AuthorizerVerifyOtp: FC<{
1818
email?: string;
1919
phone_number?: string;
2020
urlProps?: Record<string, any>;
21-
}> = ({ setView, onLogin, email, phone_number, urlProps }) => {
21+
is_totp?: boolean;
22+
}> = ({ setView, onLogin, email, phone_number, urlProps, is_totp }) => {
2223
const [error, setError] = useState(``);
2324
const [successMessage, setSuccessMessage] = useState(``);
2425
const [loading, setLoading] = useState(false);
@@ -52,7 +53,7 @@ export const AuthorizerVerifyOtp: FC<{
5253
if (urlProps?.state) {
5354
data.state = urlProps.state;
5455
}
55-
56+
data.is_totp = !!is_totp;
5657
const res = await authorizerRef.verifyOtp(data);
5758
setLoading(false);
5859

src/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { AuthorizerSocialLogin } from './components/AuthorizerSocialLogin';
1010
import { AuthorizerResetPassword } from './components/AuthorizerResetPassword';
1111
import { AuthorizerVerifyOtp } from './components/AuthorizerVerifyOtp';
1212
import { AuthorizerRoot as Authorizer } from './components/AuthorizerRoot';
13+
import { AuthorizerTOTPScanner } from './components/AuthorizerTOTPScanner';
1314

1415
export {
1516
useAuthorizer,
@@ -22,4 +23,5 @@ export {
2223
AuthorizerSocialLogin,
2324
AuthorizerResetPassword,
2425
AuthorizerVerifyOtp,
26+
AuthorizerTOTPScanner,
2527
};

src/styledComponents/StyledSeparator.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { ReactNode } from 'react';
22
import styles from '../styles/default.css';
33

4-
const StyledSeparator = ({ children }: { children: ReactNode }) => {
4+
const StyledSeparator = ({ children }: { children?: ReactNode }) => {
55
return <div className={styles['styled-separator']}>{children}</div>;
66
};
77

src/types/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,14 @@ export type AuthorizerContextPropsType = {
6161
};
6262

6363
export type OtpDataType = {
64-
isScreenVisible: boolean;
64+
is_screen_visible: boolean;
6565
email?: string;
6666
phone_number?: string;
67+
is_totp?: boolean;
6768
};
6869

6970
export type TotpDataType = {
70-
isScreenVisible: boolean;
71+
is_screen_visible: boolean;
7172
email?: string;
7273
phone_number?: string;
7374
authenticator_scanner_image: string;

0 commit comments

Comments
 (0)