简体   繁体   English

如何在 aws cognito 中收听 auth state 更改?

[英]How to listen to auth state changed in aws cognito?

I am using aws cognito for authentication solution in my react app.我在我的反应应用程序中使用 aws cognito 进行身份验证解决方案。 I am instead of using the components provided by aws react package, I am using apis in the aws javascript library.我没有使用 aws react package 提供的组件,而是使用 aws javascript 库中的 api。 I want to listen to the auth state changed.我想听一下auth state 的变化。

After googling and going over aws docs I still can't find any such method.在谷歌搜索并浏览 aws 文档后,我仍然找不到任何这样的方法。

How can I listen to changes in the auth state?如何收听 auth state 的变化?

Amplify provides a utility object called Hub that can listen to auth state changes. Amplify 提供了一个名为 Hub 的实用程序 object,它可以侦听 auth state 更改。

See sample documentation here: https://docs.amplify.aws/lib/auth/auth-events/q/platform/js请参阅此处的示例文档: https://docs.amplify.aws/lib/auth/auth-events/q/platform/js

The way I use it is by setting it up in a custom hook that gets injected into the app.tsx file.我使用它的方式是将其设置在注入 app.tsx 文件的自定义挂钩中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM