ERP-Ukraine / odoo-rpc-dart

Odoo RPC Library for Dart
MIT License
44 stars 35 forks source link

What does checkSession return? #58

Open esam12 opened 1 month ago

esam12 commented 1 month ago

Hi, Good day! Thank you for providing odoo_rpc package. I created a Flutter app and I am facing OdooSessionExpiredException problem.

Future signInWithEmailAndPassword( String database, String email, String password) async { try { // Access client final session = await client.authenticate(database, email, password);

  if (session.dbName.isNotEmpty) {
    log('Session ID From Authentication Repository: ${session.id}');
    await TLocalStorage.instance().saveData('sessionId', session.id);
  }
} catch (e) {
  throw 'Something went wrong. Please try again.';
}

}

-- As shown here the login process is done and I get the data without any problem. Since there is no problem I give it the command to go to the second page (which is Webview to display Odoo) and it goes and shows me the web page.

-- But when I restart the application I face the problem OdooSessionExpiredException.

-- This Method when the application starts, it immediately enters the catch

screenRedirect() async { await TLocalStorage.init("sessionId");

try {
  var checkSessionId = await client.checkSession();
  if (checkSessionId != true) {
    Get.offAll(() => const WebViewPage());
  } else {
    deviceStorage.writeIfNull("IsFirstTime", true);
    deviceStorage.read("IsFirstTime") != true
        ? Get.offAll(() => const LoginScreen())
        : Get.offAll(() => const OnBoardingScreen());
  }
} on Exception catch (e) {
  log('From ScreenRedirect Method ----> ${e.toString()}');
  Get.offAll(() => const LoginScreen());
}

}

-- And this Method when I enter the data as database & email & password and press the Login button on the screen

void login() async { try { /// Start Loading TFullScreenLoader.openLoadingDialog('Logging you in...', 'assets/animations/141594-animation-of-docer.json');

  /// Check internet connectivity
  final isConnected = await NetworkManager.instance.isConnected();
  if (!isConnected) {
    // Remove Loader
    TFullScreenLoader.closeLoadingDialog();
  }

  /// Form Validation
  if (!loginFormKey.currentState!.validate()) {
    // Remove Loader
    TFullScreenLoader.closeLoadingDialog();
    return;
  }

  /// Save Data if remember me is selected
  if (rememberMe.value) {
    localStorage.write('REMEMBER_ME_EMAIL', email.text.trim());
    localStorage.write('REMEMBER_ME_PASSWORD', password.text.trim());
  }

  /// Login user
  await AuthenticationRepository.instance.signInWithEmailAndPassword(
      database.text.trim(), email.text.trim(), password.text.trim());

  /// Remove Loader
  TFullScreenLoader.closeLoadingDialog();

  /// Redirect
  AuthenticationRepository.instance.screenRedirect();
} catch (e) {
  TFullScreenLoader.closeLoadingDialog();
  TLoaders.errorSnackBar(title: 'Oh Snap!', message: e.toString());
}

}

-- I did not understand the checkSession() what it returns and how to change the SessionId??

BARSHA-ABHILASHA commented 1 month ago

Same issue I faced while restarting of application but I use sharedpreference (another oneFlutter_Secure_Storage u can refer ) to store the login credentials check while login my credentials were stored or not if stored then directly get login ... but using this i am facing problem with image fetching