Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated May 16, 2024

Listen to auth events

Amplify Auth emits events during authentication flows, which enables you to react to user flows in real time and trigger custom business logic. For example, you may want to capture data, synchronize your app's state, and personalize the user's experience. You can listen to and respond to events across the Auth lifecycle such as sign-in and sign-out.

AWS Cognito Auth Plugin sends important events through Amplify Hub. You can listen to these events like the following:

final subscription = Amplify.Hub.listen(HubChannel.Auth, (AuthHubEvent event) {
switch (event.type) {
case AuthHubEventType.signedIn:
safePrint('User is signed in.');
break;
case AuthHubEventType.signedOut:
safePrint('User is signed out.');
break;
case AuthHubEventType.sessionExpired:
safePrint('The session has expired.');
break;
case AuthHubEventType.userDeleted:
safePrint('The user has been deleted.');
break;
}
});