@@ -155,7 +155,9 @@ export async function handleMFASetupChallenge({
155
155
} : HandleAuthChallengeRequest ) : Promise < RespondToAuthChallengeCommandOutput > {
156
156
const { userPoolId, userPoolClientId, userPoolEndpoint } = config ;
157
157
158
- if ( challengeResponse === 'EMAIL' ) {
158
+ const trimmedChallengeResponse = challengeResponse . trim ( ) ;
159
+
160
+ if ( trimmedChallengeResponse === 'EMAIL' ) {
159
161
return {
160
162
ChallengeName : 'MFA_SETUP' ,
161
163
Session : session ,
@@ -166,7 +168,7 @@ export async function handleMFASetupChallenge({
166
168
} ;
167
169
}
168
170
169
- if ( challengeResponse === 'TOTP' ) {
171
+ if ( trimmedChallengeResponse === 'TOTP' ) {
170
172
return {
171
173
ChallengeName : 'MFA_SETUP' ,
172
174
Session : session ,
@@ -181,7 +183,7 @@ export async function handleMFASetupChallenge({
181
183
USERNAME : username ,
182
184
} ;
183
185
184
- const isTOTPCode = / ^ \d + $ / . test ( challengeResponse . trim ( ) ) ;
186
+ const isTOTPCode = / ^ \d + $ / . test ( trimmedChallengeResponse ) ;
185
187
186
188
if ( isTOTPCode ) {
187
189
const verifySoftwareToken = createVerifySoftwareTokenClient ( {
@@ -196,7 +198,7 @@ export async function handleMFASetupChallenge({
196
198
userAgentValue : getAuthUserAgentValue ( AuthAction . ConfirmSignIn ) ,
197
199
} ,
198
200
{
199
- UserCode : challengeResponse ,
201
+ UserCode : trimmedChallengeResponse ,
200
202
Session : session ,
201
203
FriendlyDeviceName : deviceName ,
202
204
} ,
@@ -222,15 +224,18 @@ export async function handleMFASetupChallenge({
222
224
} ) ;
223
225
224
226
return respondToAuthChallenge (
225
- { region : getRegionFromUserPoolId ( userPoolId ) } ,
227
+ {
228
+ region : getRegionFromUserPoolId ( userPoolId ) ,
229
+ userAgentValue : getAuthUserAgentValue ( AuthAction . ConfirmSignIn ) ,
230
+ } ,
226
231
jsonReq ,
227
232
) ;
228
233
}
229
234
230
- const isEmail = / ^ \S + @ \S + \. \S + $ / . test ( challengeResponse . trim ( ) ) ;
235
+ const isEmail = trimmedChallengeResponse . includes ( '@' ) ;
231
236
232
237
if ( isEmail ) {
233
- challengeResponses . EMAIL = challengeResponse ;
238
+ challengeResponses . EMAIL = trimmedChallengeResponse ;
234
239
235
240
const jsonReq : RespondToAuthChallengeCommandInput = {
236
241
ChallengeName : 'MFA_SETUP' ,
@@ -247,7 +252,10 @@ export async function handleMFASetupChallenge({
247
252
} ) ;
248
253
249
254
return respondToAuthChallenge (
250
- { region : getRegionFromUserPoolId ( userPoolId ) } ,
255
+ {
256
+ region : getRegionFromUserPoolId ( userPoolId ) ,
257
+ userAgentValue : getAuthUserAgentValue ( AuthAction . ConfirmSignIn ) ,
258
+ } ,
251
259
jsonReq ,
252
260
) ;
253
261
}
0 commit comments