3

是否可以在 aws-amplify 中使用身份验证器来仅保护某些页面,以便经过身份验证的用户可以访问它们,同时仍然允许任何人访问其他页面,无论他们是否登录?我在文档示例中看到整个应用程序被强制登录,但我不确定您是否可以将某些路由包装在 react 路由器中以确保安全。

4

1 回答 1

3

该文档显示了包装整个 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'));

本教程提供了另一种方法:https ://github.com/richardzcode/Journal-AWS-Amplify-Tutorial

于 2018-03-19T17:34:35.673 回答