#Invalid UserId in react

44 messages · Page 1 of 1 (latest)

fossil vortex
#

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

#
          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);
          }
    }```
#

@raven cosmos @gray pagoda

#

@polar python

polar python
fossil vortex
#

okay

polar python
polar python
fossil vortex
polar python
fossil vortex
#

?

polar python
fossil vortex
fossil vortex
#

It is not getting solved

torn plaza
#

see

#

use ID.unique

#

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

#

like this

deep mulch
deep mulch
torn plaza
#

const newUser = await databases.createDocument(
appwriteConfig.databaseId,
appwriteConfig.userCollectionId,
ID.unique(),
user
);
is this the code for it?

#

yep this is for saving in the database or collection that is for storing in the users

fossil vortex
#

@torn plaza

torn plaza
#

sorry ig i understood it wrong then! sorry guys!

fossil vortex
deep mulch
#

if its undefined, you know the id isn't valid. in that case the value is obviously not accepted by the sdk/backend.

fossil vortex
#

suggest me solution

#

@deep mulch

deep mulch
#

how are you passing the userId, whats the value of it? current signed in user's id?

fossil vortex
deep mulch
#

the id might've been reset, override or something, how are you adding it? assuming await account.get() then getting $id?

why not do an on demand account.get() and fetch id?

fossil vortex
#

 const userData = useSelector(state => state.auth.userData);



if (file) {
    
        const fileId = file.$id
        data.featuredImage = fileId
        const dbPost = await appwriteService.createPost({
          ...data,
          userId: userData?.$id,
        })``` in postform when i post form
deep mulch
fossil vortex
deep mulch
#

if you logout, account.get() will throw an error.

fossil vortex
fossil vortex