【发布时间】:2020-11-19 02:19:59
【问题描述】:
我期待props.onStateChange,但 props 是空对象。
传递给withAuthenticator HOC 的封闭组件的道具是空的。
import { withAuthenticator } from "@aws-amplify/ui-react";
export const App = withAuthenticator((props) => {
console.log('props',props) // {}
return (
<BrowserRouter>
......
</BrowserRouter>
);
});
我想要完成的是sign-out 功能。我试过Auth.signOut()。但这只是清除localStorage,但没有重定向到sign-in页面。
我搜索了这个问题,发现
当在 withAuthenticator 中使用 Auth.signOut 时,它会 不注销,因为它只是在本地更新会话 本地存储。您需要有一种方法来重新渲染实际 withAuthenticator 组件。
https://github.com/aws-amplify/amplify-js/issues/1529
https://github.com/aws-amplify/amplify-js/issues/4643
提供的解决方案包括使用props.onStateChange,但在我的情况下,道具是空的。
我哪里错了?
【问题讨论】:
-
来自文档:withAuthenticator 是包装 AmplifyAuthenticator 的高阶组件 (HoC)。 docs.amplify.aws/lib/auth/getting-started/q/platform/…
-
@OscarNevarez 我已经更新了我的问题。您能就此提出您的意见吗?
标签: reactjs amazon-web-services aws-amplify