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

React调用auth.confirmPasswordReset()时oobCode有效仍报auth/invalid-action-code错误

问题根因

你遇到的错误是变量名大小写不匹配导致的:

  1. 在componentDidMount校验oobCode通过后,你通过this.setState({ email, oobCode })把操作码存入了state,对应的键名是驼峰格式的oobCode(字母C大写)
  2. 在onSubmit调用auth.confirmPasswordReset()时,你传的第一个参数是this.state.oobcode(字母c小写),这个键在state中不存在,实际传入方法的值是undefined,因此触发了auth/invalid-action-code报错。
解决方案

修改onSubmit方法中调用confirmPasswordReset的第一个参数,将小写c的oobcode改为大写C的oobCode即可:

onSubmit = () => {
    // 把this.state.oobcode改为this.state.oobCode
    auth.confirmPasswordReset(this.state.oobCode, this.state.newPassword).then(res => {
        this.setState({ errorText: "", passwordChanged: true })
    }).catch(err => {
        console.log('err', err)
        this.setState({ errorText: err.message })
    });
}
额外排查点

如果修改后仍有问题,可以按以下顺序排查:

  • 确认新密码长度不小于6位,符合Firebase Auth的密码强度要求,部分场景下弱密码会被误返回操作码无效的错误
  • 确认两次方法调用之间没有其他逻辑重复消费了oobCode(比如重复调用verifyPasswordResetCode或者其他接口使用了该操作码)
  • 可以在onSubmit方法开头打印this.state.oobCode和this.state.oobcode的值,确认state存储是否正常

内容的提问来源于stack exchange,提问作者Inaara Kalani

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.25 12:45:03