我正在尝试建立一个博客,在某个端点上,我只想列出由特定用户创建的所有博客,因此我已将用户信息存储在本地存储中,并且试图获取相同的用户名,这样我就可以将用户名发送到后端,以获取由该特定用户名发布的博客。
isAuth动作
export const isAuth = () => {
if(process.browser ) {
const cookieChecked = getCookie('token')
if(cookieChecked){
if(localStorage.getItem('user')){
return JSON.parse(localStorage.getItem('user'))
}else{
return false;
}
}
}
}
这是我存储在本地存储中的信息
{_id: "5ece659149421c1f18c0c756", username: "2asjvwxkq", name: "test3", email: "test3@gmail.com", role: 0}
email: "test3@gmail.com"
name: "test3"
role: 0
username: "2asjvwxkq"
_id: "5ece659149421c1f18c0c756"
I tried doing const username = isAuth() && isAuth().username
But it is returning undefined
I want to send the username
as a props to a component but the variable username
is getting me undefined value.
ı
in your localstorage , there is no parameter like
user
尝试这个 :