Skip to content
Back

Session sign-out and sign-back-in issues with records from the database

  • 0
  • Databases
  • Flutter
  • Auth
  • Cloud
Marco Napoli
3 Jan, 2025, 01:30

Session sign-out and sign-back-in issues with records from the database

In a Flutter application I am testing signing a user in, you can see the user’s records. Sign out and Sign back in. The user’s records do not show. But if you close the app or refresh the app in the simulator, the data shows up. I am testing with an iOS Simulator and iOS Device with the same results

I traced the database queries and they are being executed.

I traced the session and it’s removed, and then the correct session gets set again. It’s like the Database queries still think the session is not there, but the trace shows the correct session.

Sign out:

TypeScript
Future<void> signOut() async {
  if (_currentUser == null || _currentSession == null) {
    print('signOut error: User is not authenticated');
    return;
  }
  try {
    // Delete all sessions
    // await _account.deleteSession(sessionId: 'current');
    final result = await _account.deleteSessions();
    print('signOut result: $result');

    _currentUser = null;
    _currentSession = null;
    _authStateController.add(null);
    print('signOut success');
  } catch (e) {
    print('signOut error: $e');
  }
}

Sign in:

TypeScript
Future<Session?> signInWithEmailAndPassword({
  required String email,
  required String password,
}) async {
  try {
    // Create a new session
    final Session session = await _account.createEmailPasswordSession(
      email: email,
      password: password,
    );
    debugPrint('signInWithEmailAndPassword: ${session.userId}');

    _currentUser = await getCurrentUser();
    _currentSession = session;
    _authStateController.add(session);

    return session;
  } on AppwriteException catch (e) {
    debugPrint('signInWithEmailAndPassword error 1: $e');
    return null;
  }
}

Any thoughts?

TL;DR
Developers are experiencing session sign-out and sign-back-in issues with records not displaying after signing back in. The issue seems to be related to the database queries not recognizing the current session correctly. A potential solution can be to refresh the app or close it for the data to appear, indicating a possible caching problem.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more