Skip to content

Instantly share code, notes, and snippets.

@cdl
Created August 5, 2021 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdl/63819ae9a74b90d66942ab7f7d0939f1 to your computer and use it in GitHub Desktop.
Save cdl/63819ae9a74b90d66942ab7f7d0939f1 to your computer and use it in GitHub Desktop.
diff --git a/pages/api/posts/create.js b/pages/api/posts/create.js
index e45df89..f995100 100644
--- a/pages/api/posts/create.js
+++ b/pages/api/posts/create.js
@@ -27,7 +27,7 @@ const handlePOST = async (req, res) => {
const user = await getUserFromJWT(token);
// Otherwise, post passes validations, let's create it.
- const post = await createPost({ title, content, authorId: user.id ?? null });
+ const post = await createPost({ title, content, authorId: user?.id ?? null });
return res.json({ success: true, post });
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment