Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks done
asorokin opened this issue May 8, 2023 · 4 comments
Open
2 tasks done
Assignees
Labels
bug Something isn't working

Comments

@asorokin
Copy link

asorokin commented May 8, 2023

👟 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 asorokin added the bug Something isn't working label May 8, 2023
@asorokin asorokin changed the title 🐛 Bug Report: account.deleteSessions() Connection Timed Out on Android 🐛 Bug Report: Flutter account.deleteSessions() Connection Timed Out on Android May 8, 2023
@lohanidamodar
Copy link
Member

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

@asorokin
Copy link
Author

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!

@lohanidamodar
Copy link
Member

@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
Copy link
Member

@asorokin is this still an issue?

@abnegate abnegate assigned lohanidamodar and unassigned abnegate Mar 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants