Listen to auth events
These docs cover Amplify Gen 1. For new web apps, we recommend the latest AWS Amplify, with a simplified CLI and native integrations for databases, storage, and AI models. Get started with the latest AWS Amplify.
AWS Cognito Auth Plugin sends important events through Amplify Hub.
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; }});