remove client side post fetch

This commit is contained in:
Anton 2022-03-16 18:54:04 -04:00
parent 79a8f498c5
commit 7364eb668b

View file

@ -26,35 +26,16 @@ const Post = ({renderedPost, theme, changeTheme}: PostProps) => {
setIsLoading(true); setIsLoading(true);
if (renderedPost) { if (renderedPost) {
console.log('Using Server Side Post');
setPost(renderedPost) setPost(renderedPost)
setIsLoading(false) setIsLoading(false)
return; return;
} }
if (router.query.id) { if (post.status.toString().startsWith("4")) {
const post = await fetch(`/server-api/posts/${router.query.id}`, { router.push("/signin")
method: "GET", } else {
headers: { setError(post.statusText)
"Content-Type": "application/json",
"Authorization": `Bearer ${Cookies.get("drift-token")}`
}
})
if (post.ok) {
const res = await post.json()
if (res)
setPost(res)
else
setError("Post not found")
} else {
if (post.status.toString().startsWith("4")) {
router.push("/signin")
} else {
setError(post.statusText)
}
}
setIsLoading(false)
} }
} }
fetchPost() fetchPost()