Listen to auth events
AWS Cognito Auth Plugin sends important events through Amplify Hub.
1// Do not forget to import the following for StreamSubscription2import 'dart:async';3
4StreamSubscription<HubEvent> hubSubscription = Amplify.Hub.listen([HubChannel.Auth], (hubEvent) {5 switch(hubEvent.eventName) {6 case 'SIGNED_IN':7 print('USER IS SIGNED IN');8 break;9 case 'SIGNED_OUT':10 print('USER IS SIGNED OUT');11 break;12 case 'SESSION_EXPIRED':13 print('SESSION HAS EXPIRED');14 break;15 case 'USER_DELETED':16 print('USER HAS BEEN DELETED');17 break;18 }19});