diff --git a/lib/client/base_app_client.dart b/lib/client/base_app_client.dart index d79f0338..3aac5e92 100644 --- a/lib/client/base_app_client.dart +++ b/lib/client/base_app_client.dart @@ -22,6 +22,8 @@ class BaseAppClient { Function(String error, int statusCode) onFailure, bool isAllowAny = false}) async { String url = BASE_URL + endPoint; + + bool callLog= true; try { Map profile = await sharedPref.getObj(DOCTOR_PROFILE); String token = await sharedPref.getString(TOKEN); @@ -88,6 +90,12 @@ class BaseAppClient { if (statusCode < 200 || statusCode >= 400) { onFailure(Helpers.generateContactAdminMsg(), statusCode); } else { + if(callLog){ + callLog = false; + await AuthenticationViewModel().logout(isSessionTimeout: true); + + } + var parsed = json.decode(response.body.toString()); if (parsed['ErrorType'] == 4) { helpers.navigateToUpdatePage(parsed['ErrorEndUserMessage'], @@ -98,7 +106,7 @@ class BaseAppClient { if (body['OTP_SendType'] != null) { onFailure(getError(parsed), statusCode); } else if (!isAllowAny) { - await AuthenticationViewModel().logout(); + await AuthenticationViewModel().logout(isSessionTimeout: true); Helpers.showErrorToast('Your session expired Please login again'); } if (isAllowAny) { diff --git a/lib/core/viewModel/authentication_view_model.dart b/lib/core/viewModel/authentication_view_model.dart index d6afa270..3b8cf02f 100644 --- a/lib/core/viewModel/authentication_view_model.dart +++ b/lib/core/viewModel/authentication_view_model.dart @@ -74,7 +74,7 @@ class AuthenticationViewModel extends BaseViewModel { bool unverified = false; AuthenticationViewModel({bool checkDeviceInfo = false}) { - getDeviceInfoFromFirebase(); + getDeviceInfoFromFirebase(); getDoctorProfile(); } @@ -401,12 +401,14 @@ class AuthenticationViewModel extends BaseViewModel { } /// logout function - logout() async { + logout({bool isSessionTimeout = false}) async { DEVICE_TOKEN = ""; String lang = await sharedPref.getString(APP_Language); await Helpers.clearSharedPref(); sharedPref.setString(APP_Language, lang); ProjectViewModel().isLogin = false; + if(isSessionTimeout) + await getDeviceInfoFromFirebase(); Navigator.pushAndRemoveUntil( AppGlobal.CONTEX, FadePage( @@ -415,4 +417,9 @@ class AuthenticationViewModel extends BaseViewModel { (r) => false); } + deleteUser(){ + user = null; + notifyListeners(); + } + } diff --git a/lib/screens/auth/verification_methods_screen.dart b/lib/screens/auth/verification_methods_screen.dart index c03d5946..5aa626be 100644 --- a/lib/screens/auth/verification_methods_screen.dart +++ b/lib/screens/auth/verification_methods_screen.dart @@ -343,6 +343,8 @@ class _VerificationMethodsScreenState extends State { projectsProvider.isLogin = true; authenticationViewModel.unverified = false; authenticationViewModel.isLogin = false; + authenticationViewModel.deleteUser(); + Navigator.pushAndRemoveUntil( AppGlobal.CONTEX, FadePage(