appwrite / sdk-generator

Generating SDKs for multiple programming languages and platforms βš™οΈ

Home Page:https://appwrite.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

πŸ› Bug Report: Flutter account.deleteSessions() Connection Timed Out on Android

asorokin opened this issue Β· comments

commented

πŸ‘Ÿ 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?

  • I checked and didn't find similar issue

🏒 Have you read the Code of Conduct?

@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?

commented

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 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.

@asorokin is this still an issue?