【发布时间】:2020-12-05 07:29:24
【问题描述】:
我正在对我的 react 应用程序使用 firebase 身份验证。在我的组件中,我使用以下内容:
renderUser() {
const user = firebase.auth().currentUser;
console.log(user);
return (
<div className="nav-actions-wrapper">
{user ? (
// Display post link here
<section className="nav-actions">
<a className="btn btn-primary mr-4" href="#" onClick={this.showPostShopPopup}>
Admin Post
</a>
<PostShopPopup
user={this.props.user}
status={this.state.postShopPopupStatus}
hidePopup={this.hidePostShopPopup}
/>
</section>
) : (
<section>
<a className="btn btn-outline-primary" href="#" onClick={this.showPopup}>
Log in
</a>
<LoginPopup status={this.state.popupStatus} hidePopup={this.hidePopup} />
</section>
)}
</div>
);
}
我添加了一个自定义函数,通过自定义声明将提供的电子邮件设置为 admin: true。它工作正常,现在当我 console.log(user) 时,我在列表中看到 admin: true。
现在我怎样才能访问它以便我可以做{user.admin? ...: ...}?因为现在,当我这样做时,即使在控制台日志中它被标记为 admin: true...
【问题讨论】:
-
你能分享这个
console.log(user);的结果吗? -
它返回一个对象,其中包含有关用户的所有信息(email、emailVerified、photoURL 等以及一些其他不可读的对象和数组,包含奇怪的字母和东西)
标签: javascript reactjs firebase firebase-authentication