Listen to auth events
AWS Cognito Auth Plugin sends important events through Amplify Hub.
// Do not forget to import the following for StreamSubscriptionimport 'dart:async';
StreamSubscription<HubEvent> hubSubscription = Amplify.Hub.listen([HubChannel.Auth], (hubEvent) { switch(hubEvent.eventName) { case 'SIGNED_IN': print('USER IS SIGNED IN'); break; case 'SIGNED_OUT': print('USER IS SIGNED OUT'); break; case 'SESSION_EXPIRED': print('SESSION HAS EXPIRED'); break; case 'USER_DELETED': print('USER HAS BEEN DELETED'); break; }});