【发布时间】:2019-12-08 09:47:23
【问题描述】:
我正在尝试使用 Amplify Authenticator 在用户未登录时阻止对我的应用的访问。
<Authenticator includeGreetings={true}>
<Provider store={dataStore}>
<Router history={hist}>
<MyView>
</MyView>
</Router>
</Provider>
</Authenticator>
在我的组件 MyView 的渲染方法中,我试图通过以下方式进行简单的身份验证检查:
if (this.props.authState !== 'signedIn') {
return (<></>);
}
但由于某种原因,在 if 条件中检查 auth 状态时,它是未定义的。
-
为什么属性未定义 - 我在文档中了解到它正在向下传递到所有子组件。
- 我的方法正确吗?我从文档中看到您可以实现一个方法 showComponent(theme) 并且身份验证器只会在用户处于特定状态时调用它 但我需要在调用此方法时为身份验证器设置正确的状态 经过 this._validAuthStates = ['signedIn'];
但我不知道在哪里调用该方法,我无法在任何地方访问它。
我们将不胜感激。
【问题讨论】:
标签: reactjs amazon-web-services amazon-cognito aws-amplify