You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Redux Saga与AWS Amplify时遇TypeError: user.sendMFACode is not a function

解决redux-saga调用Auth.confirmSignIn时的sendMFACode错误

我之前在使用相同版本栈(aws-amplify 0.3.3、aws-amplify-react-native 0.2.9、redux-saga 0.15.6)时也碰到过完全一样的问题,给你分享下可行的解决方案:

问题根源

你用的call([Auth, Auth.confirmSignIn], userObj, authCode, 'SMS')这种调用方式,在redux-saga里会导致上下文绑定错误:

  • Auth.confirmSignIn内部需要调用传入的userObj的sendMFACode方法,但这种调用方式没有正确保留userObj的内部上下文,导致找不到该方法,抛出TypeError: user.sendMFACode is not a function。
  • 同时,redux-saga的这种绑定方式会触发严格模式下的限制,导致出现TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions...的错误,这两个问题是相关的。

解决方案

把调用方式改成用箭头函数包裹,确保Auth.confirmSignIn能正确访问userObj的上下文:

let confirmedUserData = yield call(() => Auth.confirmSignIn(userObj, authCode, 'SMS'));

这种方式绕开了redux-saga的上下文绑定逻辑,直接在箭头函数里执行Auth.confirmSignIn,让它内部能正常调用userObj的sendMFACode方法,同时也不会触发严格模式的错误。不用像那个已关闭的社区问题里说的替换成redux-thunk,这个方法就能直接解决问题。

内容的提问来源于stack exchange,提问作者George Ortiz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 04:03:10