autoLogin method

void autoLogin()

Implementation

void autoLogin() async {
  if (isAutoLoginTried) {
    return;
  }
  isAutoLoginTried = true;
  await Future.delayed(const Duration(seconds: 1), () {});
  if (FirebaseAuth.instance.currentUser != null) {
    Get.dialog(
        barrierColor: ColorHelper.loaderBarrierColor, const LoadingDialog());
    try {
      final loginResult =
          await Requests.createUser(FirebaseAuth.instance.currentUser!.uid);
      closeDialog();
      if (loginResult?['statusCode'] == 200) {

        if (loginResult?['role'] == 'SUPER_ADMIN' ||
            loginResult?['role'] == 'AGENT') {
          closeDialog();
          onLoginSuccessful(false);
        } else {
          FirebaseAuth.instance.signOut();
          DefaultSnackbar.show("Access denied",
              "You are not authorized to access this page, You will be redirected soon.");
          await Future.delayed(
            const Duration(seconds: 3),
          );
          html.window.location.href = 'https://nc-staging.myneoone.com/';
        }
      }
    } catch (e) {
      closeDialog();
      log('Auto-login failed: $e');
    } finally {
      closeDialog();
    }
  }
}