Back

Document Not Found after using createEmailSession, permission issue?

  • 0
  • Web
ZachHandley
1 Dec, 2023, 23:52

So I have this Auth function that runs to log a user in, and after it runs createEmailSession, I check the database for the users member document, which is just an associated document every user has that has some extra info about them in there. My question is, I get a Document not found error on first try with auth, after I log in a second time (because the error makes the function fail) it works fine, which makes me think it is authenticated but not authenticated, is that possible? If so, would a setTimeout or something fix that?

TypeScript
const login = async (email: string, password: string): Promise<{ type: string, message: string, data?: Models.User<Models.Preferences> }> => {
    try {
      const userSession = await appwrite.account.createEmailSession(email, password);
      localStorage.setItem("pvauser", JSON.stringify(userSession));
      const user = await getUser();
      $user.value = user;
      const memberTry = await getUserMember();
      if ($user.value && memberTry && memberTry.data) {
        $member.value = memberTry.data;
        const teams = await appwrite.listUserTeams();
        if (teams.data && teams.data.total > 0) {
          const membership = await appwrite.getMembershipFromUserId(teams.data.teams[0].$id, $user.value.$id);
          $membership.value = membership.data;
        }
      }
      return { type: "success", message: "Login successful", data: user };
    } catch (e) {
      console.error(e);
      return { type: "error", message: "Login failed" };
    }
  }
TL;DR
The user is experiencing a "Document not found" error when using the `createEmailSession` function in their code. They suspect it may be a permission issue. They are able to log in successfully after a second attempt. They are wondering if adding a setTimeout could fix the issue. Unfortunately, a solution to the issue is not provided in the support thread.
Drake
2 Dec, 2023, 00:21

So which part throws an error?

ZachHandley
2 Dec, 2023, 17:08

The checkUserMember which is just a list documents with query of the users ID relative to the member

Drake
3 Dec, 2023, 00:42

listDocuments returning document not found? That's odd... 🧐 does the collection have relationships?

tuyen3962
3 Dec, 2023, 03:35

Hello sir. I also face this problem

tuyen3962
3 Dec, 2023, 03:36

I have add the test data in the collection which have the relationship but i can not get both listDocuemnt and get

Drake
3 Dec, 2023, 14:35

Please create a separate post and provide all your details

tuyen3962
3 Dec, 2023, 14:38

oke thank you sir

ZachHandley
3 Dec, 2023, 18:04

No relationships

ZachHandley
3 Dec, 2023, 18:04

Filtering by using the same member ID as the Auth User ID

Drake
4 Dec, 2023, 07:48

Would you please share the code? And you're saying it's throwing an error?

ZachHandley
4 Dec, 2023, 17:24

Yes will do, one moment

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