
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
- I can't use any Oauth
Login using oauth will be rejected because the redirect url does not match but appwrite give me the redirect url is https://**************/v1/account/sessions/o...
- Changing password when logged using a OT...
I'm developping in flutter/dart, I'm using email token to login to an existing user: _sessionToken = await account.createEmailToken(userId: app.ID.unique(), ema...
- 2FA with Mail Help
Hello Appwrite Team. I would like to request Support for the following: Can you help me inserting the 2FA with Mail in my App? I don’t know how to do this... ...
