Javascript 无效令牌错误:指定的令牌无效:无法读取属性';更换';未定义的?

Javascript 无效令牌错误:指定的令牌无效:无法读取属性';更换';未定义的?,javascript,node.js,reactjs,jwt,json-web-signature,Javascript,Node.js,Reactjs,Jwt,Json Web Signature,我试图解码通过jwt创建的令牌,这样我就可以访问react页面中的值并使用它 “InvalidTokenError:Invalid token specified:Cannot read property'replace'of undefined”此错误,我确实需要这方面的帮助,非常感谢所有回答此问题的人 react.js中的前端,解码令牌 useffect(()=>{ const token=localStorage.usertoken const decoded=jwt_decode(令牌

我试图解码通过jwt创建的令牌,这样我就可以访问react页面中的值并使用它 “InvalidTokenError:Invalid token specified:Cannot read property'replace'of undefined”此错误,我确实需要这方面的帮助,非常感谢所有回答此问题的人

react.js中的前端,解码令牌

useffect(()=>{
const token=localStorage.usertoken
const decoded=jwt_decode(令牌);
setinfo({
id:已解码。\u id,
电子邮件:decoded.email,
用户名:decoded.username,
})

},[])
我认为您从本地存储访问令牌的方式是错误的。 而不是

localStorage.usertoken
使用

考虑到您已将用户令牌设置为

localStorage.setItem("userToken", token_received_from_backend);

我看不出你在哪里使用替换。您需要显示该代码。如果您没有实现replace方法,那么您应该检查堆栈跟踪,并找出函数执行了什么操作。然后确保函数在它的argsI中得到了它所需要的东西,我的代码中没有使用replace,它是在node modules包中jwt decode的index.js中使用的
localStorage.setItem("userToken", token_received_from_backend);