问题描述
您好,如果我不是很明确,请原谅,我是初学者。我做了注册模式,然后根据帐户验证(验证 = 真)发送自动电子邮件。如果帐户未经验证并且我们想在创建的站点上进行购买,我们将收到一条消息,其中包含一个用于发送确认电子邮件的按钮。我在邮递员中测试我的应用程序,我在: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 (将#修改为@)