Back

Invalid UserId in react

  • 0
  • Web
Aman
23 Sep, 2024, 15:27

I have created a blog website in REACT. When I try to post, sometimes an error is shown.

TL;DR
Developers are experiencing issues with specifying the userId attribute in a React app. The suggestion is to ensure the userId is correctly specified and to consider preventing manipulation by encapsulating the operation in a function. The provided code snippet showcases the createPost function in a blog website built with React, using Appwrite for database operations. In case of errors occurring during post creation, the console logs the corresponding error.
Aman
23 Sep, 2024, 15:27
TypeScript
          try{
            return await this.databases.createDocument(
                conf.appwriteDatabaseId,
                conf.appwriteCollectionId,
                slug,
                {
                    title,
                    content,
                    featuredImage,
                    status,
                    userId,
                }
            )
          }
          catch(error){
            console.log("Appwrite serive :: createPost :: error", error);
          }
    }```
Aman
23 Sep, 2024, 15:29

@Binyamin @Arman

Aman
23 Sep, 2024, 15:29

@D5

D5
23 Sep, 2024, 15:30

Please, avoid pinging core members if it's not necessarily 😅

Aman
23 Sep, 2024, 15:31

okay

D5
23 Sep, 2024, 15:31

Looks like userId is required, but you're not specifying it?

D5
23 Sep, 2024, 15:34

Also, do you can see the data being saved in the console at all? I think that it doesn't have a proper structure (Json-like)

Aman
23 Sep, 2024, 15:35

It's not that it never happens, sometimes it gets posted

D5
23 Sep, 2024, 15:36

Hmm then maybe you're not specifying the user ID? Anyways, I recommend doing that in a function to prevent manipulation

Aman
23 Sep, 2024, 15:38

How to specify the user ID

Aman
23 Sep, 2024, 15:38

?

D5
23 Sep, 2024, 15:41

You have here an userId attribute

Aman
23 Sep, 2024, 15:42

yup

Aman
23 Sep, 2024, 15:49

i am so frustrated

Aman
23 Sep, 2024, 15:49

It is not getting solved

lalithcs
23 Sep, 2024, 15:53

see

lalithcs
23 Sep, 2024, 15:53

use ID.unique

lalithcs
23 Sep, 2024, 15:54

const newAccount = await account.create( ID.unique(), user.email, user.password, user.name );

lalithcs
23 Sep, 2024, 15:54

like this

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