sdk-generator icon indicating copy to clipboard operation
sdk-generator copied to clipboard

🐛 Bug Report: Flutter account.deleteSessions() Connection Timed Out on Android

Open asorokin opened this issue 2 years ago • 4 comments

👟 Reproduction steps

I am developing an app using Flutter with Appwrite. When I try to log out the user by calling account.deleteSessions() on physical Android device, it throws a "Connection Timed Out" exception. The user session kept untouched in the Appwrite console. It only happens on my Android device; iOS and Web versions work as expected. Appreciate your direction on this issue.

👍 Expected behavior

Delete all sessions from the user account and remove any sessions cookies from the end client.

👎 Actual Behavior

"Connection Timed Out" exception is thrown. The user session kept untouched in the Appwrite console.

🎲 Appwrite version

Version 0.11.x

💻 Operating system

Something else

🧱 Your Environment

No response

👀 Have you spent some time to check if this issue has been raised before?

  • [X] I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

asorokin avatar May 08 '23 17:05 asorokin

@asorokin are you sure other requests are handled correctly and your android app is successfully connected to your server?

Please share some more information, not sure if the connection timed out is server related issue, if that's specific to android.

Are you testing on emulator or real device? is Appwrite server accessible from the device you are trying to make a request?

lohanidamodar avatar May 10 '23 07:05 lohanidamodar

Other requests seem to be handled correctly. I am able to login the user using the code below and I can see the user session from the Android device in the Appwrite admin panel. I can also query the collection, fetch the documents and show them in the app. It is only the log out that returns the time out error.

My Appwrite Auth class:

class AppwriteAuth {
  final Client client;

  late Account account;

  AppwriteAuth(this.client) {
    account = Account(client);
  }

  Future<appwrite.User?> getUserAccount() async {
    try {
      return await account.get();
    } on AppwriteException catch (e) {
      log(e.toString());
      return null;
    }
  }

  Future<appwrite.Session?> loginWithEmail(
    BuildContext context, {
    required String email,
    required String password,
  }) async {
    try {
      return await account.createEmailSession(email: email, password: password);
    } catch (e) {
      await showDialog(
        context: context,
        builder: (BuildContext context) => AlertDialog(
          title: const Text('Aw, Snap! That didn\'t work :/'), // TODO implement Translations
          content: Text(e.toString()),
          actions: [
            TextButton(
              onPressed: () {
                Navigator.of(context).pop();
              },
              child: const Text('Ok'),
            ),
          ],
        ),
      );
      return null;
    }
  }

  Future<appwrite.User?> signUpWithEmail(BuildContext context,
      {required String email, required String password, String? name}) async {
    try {
      final appwrite.User user = await account.create(email: email, password: password, userId: 'unique()', name: name);

      account.createEmailSession(email: email, password: password);

      return user;
    } catch (e) {
      log(" Sign Up $e");
      await showDialog(
        context: context,
        builder: (BuildContext context) => AlertDialog(
          title: const Text('Aw, Snap! That didn\'t work :/'),
          content: Text(e.toString()),
          actions: [
            TextButton(
              onPressed: () {
                Navigator.of(context).pop();
              },
              child: const Text("Ok"),
            )
          ],
        ),
      );
      return null;
    }
  }

  Future<void> logout(BuildContext context) async {
    const indicatorWidget = Center(child: CircularProgressIndicator());
    try {
      DialogHelpers.showProgressDialog(context, indicatorWidget);

      await account.deleteSessions();

      if (context.mounted) {
        DialogHelpers.hideProgressDialog(context, indicatorWidget);
        Navigator.of(context).pushReplacementNamed(LoginEmailPage.routename);
      }
    } on AppwriteException catch (e) {
      final String errorMessage = e.message != null ? e.message.toString().substring(13).split('<')[0] : '';
      DialogHelpers.hideProgressDialog(context, indicatorWidget);
      await showDialog(
        context: context,
        builder: (BuildContext context) => AlertDialog(
          title: const Text('Aw, Snap! That didn\'t work :/'),
          content: Text(errorMessage),
          actions: [
            TextButton(
              onPressed: () {
                Navigator.of(context).pop();
              },
              child: const Text('Ok'),
            )
          ],
        ),
      );
    }
  }
}

The loginWithEmail method works successfully on all platforms I implement Android, iPhone, Web. However the logout method with calling the account.deleteSessions() only works on iPhone and Web, but not on Android.

Appwrite sessions shows the user: image

Apprite user activity shows session.created, but doesn't show session deleted (if the user logins from a browser or iPhone the session.delete works fine). image

I am testing on a physical Android device.

Appreciate any direction/suggestions on my issue.

Thanks!

asorokin avatar May 18 '23 19:05 asorokin

@asorokin instead of deleteSessions for logout, which deletes session from all the devices, can you try account.deleteSession('current') which deletes the active session.

Still we will explore further if we can reproduce the issue with deleteSessions.

lohanidamodar avatar May 21 '23 01:05 lohanidamodar

@asorokin is this still an issue?

lohanidamodar avatar Jan 02 '24 00:01 lohanidamodar

closing due to stale

ChiragAgg5k avatar Jul 29 '25 10:07 ChiragAgg5k