@@ -155,7 +155,9 @@ export async function handleMFASetupChallenge({
155155} : HandleAuthChallengeRequest ) : Promise < RespondToAuthChallengeCommandOutput > {
156156 const { userPoolId, userPoolClientId, userPoolEndpoint } = config ;
157157
158- if ( challengeResponse === 'EMAIL' ) {
158+ const trimmedChallengeResponse = challengeResponse . trim ( ) ;
159+
160+ if ( trimmedChallengeResponse === 'EMAIL' ) {
159161 return {
160162 ChallengeName : 'MFA_SETUP' ,
161163 Session : session ,
@@ -166,7 +168,7 @@ export async function handleMFASetupChallenge({
166168 } ;
167169 }
168170
169- if ( challengeResponse === 'TOTP' ) {
171+ if ( trimmedChallengeResponse === 'TOTP' ) {
170172 return {
171173 ChallengeName : 'MFA_SETUP' ,
172174 Session : session ,
@@ -181,7 +183,7 @@ export async function handleMFASetupChallenge({
181183 USERNAME : username ,
182184 } ;
183185
184- const isTOTPCode = / ^ \d + $ / . test ( challengeResponse . trim ( ) ) ;
186+ const isTOTPCode = / ^ \d + $ / . test ( trimmedChallengeResponse ) ;
185187
186188 if ( isTOTPCode ) {
187189 const verifySoftwareToken = createVerifySoftwareTokenClient ( {
@@ -196,7 +198,7 @@ export async function handleMFASetupChallenge({
196198 userAgentValue : getAuthUserAgentValue ( AuthAction . ConfirmSignIn ) ,
197199 } ,
198200 {
199- UserCode : challengeResponse ,
201+ UserCode : trimmedChallengeResponse ,
200202 Session : session ,
201203 FriendlyDeviceName : deviceName ,
202204 } ,
@@ -222,15 +224,18 @@ export async function handleMFASetupChallenge({
222224 } ) ;
223225
224226 return respondToAuthChallenge (
225- { region : getRegionFromUserPoolId ( userPoolId ) } ,
227+ {
228+ region : getRegionFromUserPoolId ( userPoolId ) ,
229+ userAgentValue : getAuthUserAgentValue ( AuthAction . ConfirmSignIn ) ,
230+ } ,
226231 jsonReq ,
227232 ) ;
228233 }
229234
230- const isEmail = / ^ \S + @ \S + \. \S + $ / . test ( challengeResponse . trim ( ) ) ;
235+ const isEmail = trimmedChallengeResponse . includes ( '@' ) ;
231236
232237 if ( isEmail ) {
233- challengeResponses . EMAIL = challengeResponse ;
238+ challengeResponses . EMAIL = trimmedChallengeResponse ;
234239
235240 const jsonReq : RespondToAuthChallengeCommandInput = {
236241 ChallengeName : 'MFA_SETUP' ,
@@ -247,7 +252,10 @@ export async function handleMFASetupChallenge({
247252 } ) ;
248253
249254 return respondToAuthChallenge (
250- { region : getRegionFromUserPoolId ( userPoolId ) } ,
255+ {
256+ region : getRegionFromUserPoolId ( userPoolId ) ,
257+ userAgentValue : getAuthUserAgentValue ( AuthAction . ConfirmSignIn ) ,
258+ } ,
251259 jsonReq ,
252260 ) ;
253261 }
0 commit comments