微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

重新发送电子邮件验证 MERN

如何解决重新发送电子邮件验证 MERN

您好,如果我不是很明确,请原谅,我是初学者。我做了注册模式,然后根据帐户验证(验证 = 真)发送自动电子邮件。如果帐户未经验证并且我们想在创建的站点上进行购买,我们将收到一条消息,其中包含一个用于发送确认电子邮件的按钮。我在邮递员中测试我的应用程序,我在:localhost:3001/api/users/resend 上发帖,我进入标题授权...持有人 {token} 并重新发送工作。但在客户端,出了点问题:

回复

POST http://localhost:3000/api/users/resend 401 (Unauthorized)

如果我没有在邮递员中放入正确的令牌,响应是相同的:未经授权,但返回的令牌是可以的,并且在 axios.post 中必须是可以的.... 服务器中的功能

async resendmail(req,res,next) {
  try {
    //find user by email
    const user = await userService.GasUserPrinEmail(req.user.email);
    //token for auth            
    const token = await authService.Autentificaretoken(user);

    //send mail
    await emailService.inregistrareEmail(user.email,user);

    res.cookie('cookie_token',token)
      .send({
        user,token
      })
  } catch (error) {
    next(error);
  }
}

客户端函数

export const userResend = () => {
  return async (dispatch,getState) => {
    try { //this console is show,if i coppy from console token and put it in postman is working
      console.log(getTokenCookie());
      const user = await axios.post(`/api/users/resend`,{
        headers: {
          'Authorization': `Bearer ${getTokenCookie()}`
        }
      });
      //this console don t show
      console.log(getTokenCookie());
      dispatch(actions.userAuthenticate({
        data: user.data.user,auth: true
      }))
      dispatch(actions.successGlobal('Bine ai venit! Tocmai a fost trimis un email catre dvs,valideaza contul!'))
    } catch (error) {
      dispatch(actions.errorGlobal(error.response.data.message))

    }
  }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。