【问题标题】:AWS-Amplify Authenticator supporting authenticated and non-authenticated pagesAWS-Amplify Authenticator 支持经过身份验证和未经身份验证的页面
【发布时间】:2018-03-08 18:04:35
【问题描述】:

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

【问题讨论】:

    标签: reactjs react-router aws-amplify


    【解决方案1】:

    文档显示了包装整个 App 类的示例。一种最简单的替代方法是 withAuthenticator(Whatever_Component_That_Requires_Auth) 而不是整个 App。

    或者使用Authenticator 组件代替withAuthenticator HOC 具有更大的灵活性。

    另一种方法是从组件中的 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

    【讨论】:

      猜你喜欢
      • 2019-02-09
      • 1970-01-01
      • 2019-09-25
      • 1970-01-01
      • 2017-07-01
      • 2016-01-17
      • 2019-01-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多