@@ -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 } ,
@@ -227,10 +229,10 @@ export async function handleMFASetupChallenge({
227229 ) ;
228230 }
229231
230- const isEmail = / ^ \S + @ \S + \. \S + $ / . test ( challengeResponse . trim ( ) ) ;
232+ const isEmail = / ^ \S + @ \S + \. \S + $ / . test ( trimmedChallengeResponse ) ;
231233
232234 if ( isEmail ) {
233- challengeResponses . EMAIL = challengeResponse ;
235+ challengeResponses . EMAIL = trimmedChallengeResponse ;
234236
235237 const jsonReq : RespondToAuthChallengeCommandInput = {
236238 ChallengeName : 'MFA_SETUP' ,
0 commit comments