React Native 中的密码重置不起作用

问题描述

我正在创建密码重置,我必须在我的数据库中提供一个现有的电子邮件,以便我可以更改其密码

这是我的方法

router.post('/new-password',async (req,res) => {
    const newPassword = req.body.password
    
    User.findOne({ email: req.body.email }).then(user => {

            if (!user) {
                console.log("new-password user",user)
                return res.status(422).json({ error: "Try again session expired" })
            }
            bcrypt.hash(newPassword,12).then(hashedpassword => {
                user.password = hashedpassword
                user.save()
                try {
                    const token = jwt.sign({ userId: user._id },jwtkey)
                    res.send({ token })
                } catch (err) {
                    return res.status(422).send({ error: "error token " })
                }

            })
        }).catch(err => {
            console.log(err)
        })
})

PostData =async()=>  {
       fetch("http://10.0.2.2:4000/new-password",{
            method: "post",headers: {
                "Content-Type": "application/json"
            },body: JSON.stringify({
                "password": this.state.password,"email": this.state.recovery_email

             
            })
        }).then(res => res.json())
            .then(async(data) => {
                console.log(data)
                if (data.error) {
                    alert("error")
                }
                else {
                    await AsyncStorage.setItem('token',data.token)
                    alert("mot de passe changee")
                    this.props.navigation.replace("Login")
                }
            }).catch(err => {
                console.log(err)
            })
    }

这里一切正常,我可以更改密码并签署新令牌,但是每当我尝试使用新密码登录时,我都会收到错误

enter image description here

这是我的登录代码页,我使用 asyncstorage 将令牌放入其中

  const SendUserInfo = async () => {
        fetch("http://10.0.2.2:4000/signin",{
            method: "POST",headers: {
                'Content-Type': 'application/json'
            },body: JSON.stringify({

                "email": email,"password": password
            })
        })
            .then(res => res.json())
            .then(async (data) => {
                try {
                    console.log("Logged in !")
                    await AsyncStorage.setItem('token',data.token)
                    navigation.replace("MyTabs")
                } catch (e) {
                    alert("Verifier vos donnes")
                    console.log(e)
                   
                }
            })
        
    }

有什么解决办法吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)