angelo
angelo

Reputation: 2961

How to listen to auth state changed in aws cognito?

I am using aws cognito for authentication solution in my react app. I am instead of using the components provided by aws react package, I am using apis in the aws javascript library. I want to listen to the auth state changed.

After googling and going over aws docs I still can't find any such method.

How can I listen to changes in the auth state?

Upvotes: 1

Views: 2228

Answers (1)

esther h
esther h

Reputation: 1468

Amplify provides a utility object called Hub that can listen to auth state changes.

See sample documentation here: 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.

Upvotes: 2

Related Questions