#Couldn't read document even though a session exist

15 messages · Page 1 of 1 (latest)

median lava
#

Hello Everyone,
When I log in to the app, I try to retrieve data in my collection from an ID. This is the ID of the user's document.

✅ The user is logged in

However, I get an error message telling me that the document I'm trying to read does not exist.
When I look in the collection in Appwrite, I see that the document is indeed present.
Permissions: the document is only accessible by users and i'm logged in

Can someone tell me where the problem could come from? because I really don't understand

dusk tiger
#

Sanity check -> are you looking in the right collection with the right project ID set?

median lava
#

it is the right collection and the right ID. I checked several times

tawdry vale
median lava
#

Code to load data from server :

// After user logged in 
final user = await account.get(); // Get account data
Provider.of<UserDataProvider>(context, listen: false).loadUserData(user.$id); // Call function in user data provider

// In provider .file
// Get and store data in variables
void loadUserData(String userId) async {
    await getUserData(userID: userId).then((userData){

      if (userData != null) {
        _userId = userData['user_uid'];
        _userDeviceToken = userData['user_token'];
        _mbreDesc = userData['description'];
        notifyListeners();
      }

    });

  }

**********************************************************************
// In other .dart file
Future getUserData({
  required String userID,
}) async {
  try{
    
    print("UID $userID"); // Print show that the variable userID is not empty with the correct userID
    // Get data from server
    final response = await databases.getDocument( <------- AT THIS POINT FUNCTION BREAK AND I GOT ERROR "AppwriteException: document_not_found, Document with the requested ID could not be found. (404)"
      databaseId: db,
      collectionId: userCollection,
      documentId: userID,
    );

    return response.data;
  } catch (e) {
  
    print(e.toString());
    return "error_during_getting_user_data";
  }
}
median lava
#

Additional informations :

When I start app with Flutter run (F5) I get Login Screen -------> ✅
After login, all data a correctly imported from Appwriter database online -------> ✅

PROBLEM : When i logout, and try again to login again, I get now error : -------> ❌

It's a no sense.

I'm log out with

median lava
#

Couldn't read document even though a session exist

median lava
dusk tiger
#

When do you create the user collection and write to it?

#

also make sure it's ur user ID and not session ID you're storing

median lava
burnt kindle
#

Are you also sure your security settings for that collection allows the user to read?

Check collection permissions & document security

dusk tiger
median lava