@@ -6,11 +6,22 @@ import { ButtonAppearance, MessageType, Views } from '../constants';
66import { useAuthorizer } from '../contexts/AuthorizerContext' ;
77import { StyledButton , StyledFooter , StyledLink } from '../styledComponents' ;
88import { Message } from './Message' ;
9+ import { TotpDataType } from '../types' ;
10+ import { AuthorizerTOTPScanner } from './AuthorizerTOTPScanner' ;
911
1012interface InputDataType {
1113 otp : string | null ;
1214}
1315
16+ const initTotpData : TotpDataType = {
17+ is_screen_visible : false ,
18+ email : '' ,
19+ phone_number : '' ,
20+ authenticator_scanner_image : '' ,
21+ authenticator_secret : '' ,
22+ authenticator_recovery_codes : [ ] ,
23+ } ;
24+
1425export const AuthorizerVerifyOtp : FC < {
1526 setView ?: ( v : Views ) => void ;
1627 onLogin ?: ( data : any ) => void ;
@@ -22,6 +33,7 @@ export const AuthorizerVerifyOtp: FC<{
2233 const [ error , setError ] = useState ( `` ) ;
2334 const [ successMessage , setSuccessMessage ] = useState ( `` ) ;
2435 const [ loading , setLoading ] = useState ( false ) ;
36+ const [ totpData , setTotpData ] = useState < TotpDataType > ( { ...initTotpData } ) ;
2537 const [ sendingOtp , setSendingOtp ] = useState ( false ) ;
2638 const [ isLockedOut , setIsLockedOut ] = useState ( false ) ;
2739 const [ formData , setFormData ] = useState < InputDataType > ( {
@@ -73,6 +85,26 @@ export const AuthorizerVerifyOtp: FC<{
7385 setError ( errors [ 0 ] ?. message || `` ) ;
7486 return ;
7587 }
88+
89+ // If TOTP validated using recovery code then show totp screen with scanner
90+ if (
91+ res &&
92+ res . should_show_totp_screen &&
93+ res . authenticator_scanner_image &&
94+ res . authenticator_secret &&
95+ res . authenticator_recovery_codes
96+ ) {
97+ setTotpData ( {
98+ is_screen_visible : true ,
99+ email : data . email || `` ,
100+ phone_number : data . phone_number || `` ,
101+ authenticator_scanner_image : res . authenticator_scanner_image ,
102+ authenticator_secret : res . authenticator_secret ,
103+ authenticator_recovery_codes : res . authenticator_recovery_codes ,
104+ } ) ;
105+ return ;
106+ }
107+
76108 if ( res ) {
77109 setError ( `` ) ;
78110 setAuthData ( {
@@ -138,6 +170,24 @@ export const AuthorizerVerifyOtp: FC<{
138170 }
139171 } , [ formData . otp ] ) ;
140172
173+ if ( totpData . is_screen_visible ) {
174+ return (
175+ < AuthorizerTOTPScanner
176+ { ...{
177+ setView,
178+ onLogin,
179+ email : totpData . email || `` ,
180+ phone_number : totpData . phone_number || `` ,
181+ authenticator_scanner_image : totpData . authenticator_scanner_image ,
182+ authenticator_secret : totpData . authenticator_secret ,
183+ authenticator_recovery_codes :
184+ totpData . authenticator_recovery_codes || [ ] ,
185+ } }
186+ urlProps = { urlProps }
187+ />
188+ ) ;
189+ }
190+
141191 return (
142192 < >
143193 { successMessage && (
0 commit comments