Back

server status 500 when trying to add a post

  • 1
  • Storage
stella
19 Dec, 2023, 08:42

import { zodResolver } from "@hookform/resolvers/zod" import { useForm } from "react-hook-form" import * as z from "zod" import { useNavigate } from "react-router-dom";

import { Button } from "@/components/ui/button" import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form" import { Input } from "@/components/ui/input" import { Textarea } from "../ui/textarea" import FileUploader from "../shared/FileUploader" import { PostValidation } from "@/lib/validation" import { Models } from "appwrite" import { useUserContext } from "@/context/AuthContext" import { useToast } from "../ui/use-toast" import { useCreatePost } from "@/lib/react-query/queriesAndMutations";

type PostFormProps = { post?: Models.Document; }

const PostForm = ({ post }: PostFormProps) => { const { mutateAsync: createPost, isPending: isLoadingCreate } = useCreatePost(); const { user } = useUserContext(); const { toast } = useToast(); const navigate = useNavigate();

TypeScript
// 1. Define your form schema.

const form = useForm<z.infer<typeof PostValidation>>({ resolver: zodResolver(PostValidation), defaultValues: { caption: post ? post?.caption : "", file: [], location: post ? post?.location : "", tags: post ? post.tags.join(',') : "" }, })

// 2. Define a submit handler. async function onSubmit(values: z.infer<typeof PostValidation>) { const newPost = await createPost({ ...values, userId: user.id, }) if(!newPost) { toast({ title: 'Please try again' }) } navigate('/');

TL;DR
The user is experiencing a server status 500 error when trying to add a post. They are using a form to create a post and are trying to limit access to certain users. The user may need to set permissions for the document and check if any attributes are pending or failed. The error message in the console does not show any errors. The user should try adding three backticks at the start and end of their code for easier readability. They should also provide their project id. Overall, it seems that the issue is still unresolved.
Haimantika
19 Dec, 2023, 08:43

Also, please share your project id

stella
19 Dec, 2023, 08:43

VITE_APPWRITE_PROJECT_ID='657b55c396bd6978305a'

Haimantika
19 Dec, 2023, 08:44

Btw, for easier readability of code, it is better to enclose it within three backticks `

stella
19 Dec, 2023, 08:45

i am in the learning process... how do i do that?

Haimantika
19 Dec, 2023, 08:45

Just add this backtick thrice at the start and end of your code

stella
19 Dec, 2023, 08:46

okay

Haimantika
19 Dec, 2023, 08:49

@stella can you share a screenshot of the attributes from the console?

stella
19 Dec, 2023, 08:51

sure

stella
19 Dec, 2023, 08:52

console error message?

stella
19 Dec, 2023, 08:54

before it was status 500 but at the moment no error in console

Haimantika
19 Dec, 2023, 09:03

Nope, the attributes you created. Can you show a screenshot of that?

Haimantika
19 Dec, 2023, 09:03

That means it is working now? 🤔

stella
19 Dec, 2023, 09:04

let me share

stella
19 Dec, 2023, 09:04

no it has not added post to appwrite

stella
19 Dec, 2023, 09:05
stella
19 Dec, 2023, 09:06
Haimantika
19 Dec, 2023, 09:08

Are any attributes pending or failed?

stella
19 Dec, 2023, 09:10

not sure😫

Haimantika
19 Dec, 2023, 09:13

You will be able to see it in the console itself 😅

stella
19 Dec, 2023, 09:17

let me see

D5
19 Dec, 2023, 10:46

Do you have set permissions?

1976satch9
19 Dec, 2023, 14:09

when you create a document you must precise after the data an array for permission like this [ Permission.write(Role.any()) but it depends of the role for this table. for me i put in settings of my table role : any

D5
19 Dec, 2023, 15:02

Role.any will make everyone access to it and the user maybe wants to limit access to some users

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