@@ -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
} ,
@@ -227,10 +229,10 @@ export async function handleMFASetupChallenge({
227
229
) ;
228
230
}
229
231
230
- const isEmail = / ^ \S + @ \S + \. \S + $ / . test ( challengeResponse . trim ( ) ) ;
232
+ const isEmail = / ^ \S + @ \S + \. \S + $ / . test ( trimmedChallengeResponse ) ;
231
233
232
234
if ( isEmail ) {
233
- challengeResponses . EMAIL = challengeResponse ;
235
+ challengeResponses . EMAIL = trimmedChallengeResponse ;
234
236
235
237
const jsonReq : RespondToAuthChallengeCommandInput = {
236
238
ChallengeName : 'MFA_SETUP' ,
0 commit comments