add session time out.

auth_refactor
Elham Rababah 5 years ago
parent a9bd02a908
commit 6933b6577f

@ -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) {

@ -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();
}
}

@ -343,6 +343,8 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
projectsProvider.isLogin = true;
authenticationViewModel.unverified = false;
authenticationViewModel.isLogin = false;
authenticationViewModel.deleteUser();
Navigator.pushAndRemoveUntil(
AppGlobal.CONTEX,
FadePage(

Loading…
Cancel
Save