reactjs - aws-放大反应。身份验证器组件 - 注销按钮
问题描述
下列的
https://aws-amplify.github.io/docs/js/authentication#using-the-authenticator-component-directly
import { Authenticator} from 'aws-amplify-react'
import Amplify from 'aws-amplify';
import aws_exports from './aws_exports';
Amplify.configure(aws_exports);
const AppWithAuth = () => (
<Authenticator>
<App/>
</Authenticator>
)
export default AppWithAuth
我正在尝试直接使用 Authenicator 组件。登录后如何显示退出按钮。
尝试遵循 https://github.com/richardzcode/Journal-AWS-Amplify-Tutorial/tree/master/step-02#sign-out-button
import { Authenticator , SignOut} from 'aws-amplify-react'
const AppWithAuth = () => (
<Authenticator>
<SignOut />
<App/>
</Authenticator>
)
但是注销按钮仍然不可见
解决方案
这不会使用 SignOut 组件,而是另一种注销方式。您需要创建自己的 signOut 按钮。
这取自https://aws-amplify.github.io/docs/js/authentication 所以在导航栏或任何你想创建你的注销按钮的地方,你可以添加:
signOut = () => {
Auth.signOut()
.then(data => console.log(data))
.catch(err => console.log(err));
}
// Then in your render method.
<button onClick={this.signOut} className="signOutButton">SignOut</button>
它要求您使用“withAuthenticator”包装您的 App 导出
所以 fx 在你的 App.js 中
import React, { Component } from "react";
import { withAuthenticator } from "aws-amplify-react";
class App extends Component {
...
}
export default withAuthenticator(App, false);
这里的 false 表示没有 sigOut 按钮。如果您使用 true 尝试它,您将获得 Default signOut 按钮。
在此之后,您可以随意设置按钮的样式。希望这可以帮助!
推荐阅读
- python - scipy 最小化在优化期间不探索所有样本空间
- c++ - c++ g++ 编译器 - 错误:隐式声明的定义
- javascript - 如何在对象数组中获取特定的键和值
- c# - 如何使用字符串从多个类中获取变量的值
- javascript - 如何在 ServiceNow 工作流运行脚本中获取表单的字段值
- python - Pyspark 发现不同模式的 2 个数据帧之间的差异
- mongodb - MongoDB在Java驱动程序中聚合之前将String转换为Int
- chisel - 在 CHISEL 中打印 UInt 和 SInt 值
- android - 反应本机 - 未找到任务 $,无法启动应用程序
- oracle-apex - 使 oracle apex 菜单项默认折叠,目前在 oracle apex 20.1 中默认展开