
const submit = async (data) => { if (post) { const file = data.image[0] ? await appwriteService.uploadFile(data.image[0]) : null;
TypeScript
if (file) {
appwriteService.deleteFile(post.featuredImage);
}
const dbPost = await appwriteService.updatePost(post.$id, {
...data,
featuredImage: file ? file.$id : undefined,
});
if (dbPost) {
navigate(`/post/${dbPost.$id}`);
}
} else {
const file = await appwriteService.uploadFile(data.image[0]);
if (file) {
const fileId = file.$id;
data.featuredImage = fileId;
const dbPost = await appwriteService.createPost({ ...data, userId: userData.$id });
if (dbPost) {
navigate(`/post/${dbPost.$id}`);
}
}
}
};
TL;DR
Error in code due to trying to access property $id of undefined post. Need to ensure post is not undefined before accessing properties.Recommended threads
- Custom SMS providers for OTP
Is there is any way that we can add custom SMTP servers for sending OTPs. We are seeing issues with appwrite default provider, it doesn't send otps for some num...
- Custom Auth flows
Is there a way to create a user session with just the username from admin client ? We want to implement custom auth flow , once we verify every thing, we want ...
- Appwrite OAuth2 RefreshToken Logic
For some context, I'm a beginner that is trying to figure out how to work with appwrite and oauth2 and I'd appreciate any help I can get. I'm currently trying t...
