#[SOLVED] AppwriteException: The current user is not authorized to perform the requested action

73 messages · Page 1 of 1 (latest)

night urchin
#

Can you check the permission?

molten blaze
#

Where does this error show? In the Console, in your application? What were you trying to do?

sonic moat
#

in the console I'm trying to create post

#

pushing img comment,..

sonic moat
molten blaze
sonic moat
#

I will share my code soon

#

Now I'm not at my pc

sonic moat
# sonic moat
  const { toast } = useToast();
  const navigate = useNavigate();
  const { checkAuthUser, isLoading: isUserLoading } = useUserContext();

  // Query
  const { mutateAsync: signInAccount, isLoading } = useSignInAccount();

  const form = useForm<z.infer<typeof SigninValidation>>({
    resolver: zodResolver(SigninValidation),
    defaultValues: {
      email: "",
      password: "",
    },
  });

  const handleSignin = async (user: z.infer<typeof SigninValidation>) => {
    const session = await signInAccount(user);

    if (!session) {
      toast({ title: "Login failed. Please try again." });
      
      return;
    }

    const isLoggedIn = await checkAuthUser();

    if (isLoggedIn) {
      form.reset();

      navigate("/");
    } else {
      toast({ title: "Login failed. Please try again.", });
      
      return;
    }
  };```
#

unable to login

sonic moat
night urchin
sonic moat
#

yup

molten blaze
# sonic moat

What function are you using that's triggering the error?

molten blaze
sonic moat
#

different is Vue vs react

sonic moat
molten blaze
# sonic moat handleSignin

I don't see any function here called isLoggedIn? All I see is a var, which calls a function called checkAuthUser(). If that's what you're referring to, what does that function do? Could we please see that?

molten blaze
# sonic moat see this

That isn't an error, it's a warning which you don't really need to worry about during development

molten blaze
molten blaze
# sonic moat
  • Are Document Level Permissions enabled?
  • Is it possible this Collection has a Relationship with another Collection which has different permissions?
sonic moat
sonic moat
sonic moat
molten blaze
#

You still haven't answered what you're actually doing that's triggering this

sonic moat
molten blaze
sonic moat
#

btw what do you mean by document level i just know this

molten blaze
sonic moat
sonic moat
# sonic moat

and after directly login i'm creating post and posting that toDB

sonic moat
# sonic moat

there i'm unable to post it to db getting this error

molten blaze
sonic moat
#

using react query

#
  try {
    // Upload file to appwrite storage
    const uploadedFile = await uploadFile(post.file[0]);

    if (!uploadedFile) throw Error;

    // Get file url
    const fileUrl = getFilePreview(uploadedFile.$id);
    if (!fileUrl) {
      await deleteFile(uploadedFile.$id);
      throw Error;
    }

    // Convert tags into array
    const tags = post.tags?.replace(/ /g, "").split(",") || [];

    // Create post
    const newPost = await databases.createDocument(
      appwriteConfig.databaseId,
      appwriteConfig.postCollectionId,
      ID.unique(),
      {
        creator: post.userId,
        caption: post.caption,
        imageUrl: fileUrl,
        imageId: uploadedFile.$id,
        location: post.location,
        tags: tags,
      }
    );

    if (!newPost) {
      await deleteFile(uploadedFile.$id);
      throw Error;
    }

    return newPost;
  } catch (error) {
    console.log(error);
  }
}```
molten blaze
sonic moat
#

ya

#

yes

sonic moat
molten blaze
sonic moat
#
    console.log(error);
  }```
molten blaze
sonic moat
#

firstly i got error by tag

#

tags: tags,

molten blaze
sonic moat
#

no its line 149 in my editor

#

124 is const uploadedFile = await uploadFile(post.file[0]);

molten blaze
sonic moat
#

after removing tag the error is gone

sonic moat
molten blaze
molten blaze
sonic moat
# molten blaze That's... uh... not a function
  try {
    // Upload file to appwrite storage
    const uploadedFile = await uploadFile(post.file[0]);

    if (!uploadedFile) throw Error;

    // Get file url
    const fileUrl = getFilePreview(uploadedFile.$id);
    if (!fileUrl) {
      await deleteFile(uploadedFile.$id);
      throw Error;
    }

    // Convert tags into array
    const tags = post.tags?.replace(/ /g, "").split(",") || [];

    // Create post
    const newPost = await databases.createDocument(
      appwriteConfig.databaseId,
      appwriteConfig.postCollectionId,
      ID.unique(),
      {
        creator: post.userId,
        caption: post.caption,
        imageUrl: fileUrl,
        imageId: uploadedFile.$id,
        location: post.location,
        // tags: tags,
      }
    );

    if (!newPost) {
      await deleteFile(uploadedFile.$id);
      throw Error;
    }

    return newPost;
  } catch (error) {
    console.log(error);
  }
}``` this full function
sonic moat
#

    //  Update post
    const updatedPost = await databases.updateDocument(
      appwriteConfig.databaseId,
      appwriteConfig.postCollectionId,
      post.postId,
      {
        caption: post.caption,
        imageUrl: image.imageUrl,
        imageId: image.imageId,
        location: post.location,
        tags: tags,
      }```
#

this was not working

sonic moat
#

thanks for your support

molten blaze
#

If your issue has been solved, you can close this post by adding “[SOLVED]” to the beginning of the title

#

No, to the title

sonic moat
#

AppwriteException: The current user is not authorized to perform the requested action [SOLVED]

molten blaze
#

To the beginning of the title

sonic moat
#

kkk