我目前正在开发一个博客应用程序。我将react js用于前端,将node js用于后端。我有这个isAuthenticated方法。
export const isAuthenticated = () => {
if (typeof window == 'undefined') {
return false;
}
if (localStorage.getItem('jwt')) {
return JSON.parse(localStorage.getItem('jwt'));
}
else {
return false;
}};
我在这里用
<li className="nav-item">
<Link
to={`/user/${isAuthenticated().user._id}`}
style={isActive(history, `/user/${isAuthenticated().user._id}`)}
className="nav-link"
>
{`${isAuthenticated().user.name}'s profile`}
</Link>
</li>
And it's giving me error of TypeError: Cannot read property '_id' of undefined in
to={/user/${isAuthenticated().user._id}
} this part
Here is my source code for react https://github.com/mervegb/reactmerve
for nodejs https://github.com/mervegb/merveblog
请帮助我库存不足,我无法从后端获取_id,但是每当我单击Google chrome开发工具中的应用程序时,我都可以jwt令牌