Chr*_*ger 4 reactjs react-router aws-amplify
是否可以使用 aws-amplify 中的身份验证器仅保护某些页面,以便经过身份验证的用户可以访问它们,同时仍然允许任何人访问其他页面,无论他们是否登录?我在文档示例中看到整个应用程序被迫登录,但我不确定是否可以将某些路由包装在反应路由器内以确保安全。
小智 6
该文档显示了包装整个 App 类的示例。一种最简单的替代方法是使用 withAuthenticator(Whatever_Component_That_Requires_Auth) 而不是整个应用程序。
或者使用Authenticator组件代替withAuthenticatorHOC 以获得更多灵活性。
另一种方法是从组件中的 API 检查身份验证状态。
import { Auth } from 'aws-amplify';
Auth.currentAuthenticatedUser()
.then(user => console.log('is in'))
.catch(err => console.log('is not in'));
Run Code Online (Sandbox Code Playgroud)
本教程提供了另一种方法:https ://github.com/richardzcode/Journal-AWS-Amplify-Tutorial
| 归档时间: |
|
| 查看次数: |
2877 次 |
| 最近记录: |