CoastalCommitsPastes/client/app/mine/page.tsx

31 lines
773 B
TypeScript
Raw Normal View History

import { redirect } from "next/navigation"
2022-12-04 04:31:51 -05:00
import { getPostsByUser, User } from "@lib/server/prisma"
2022-11-12 04:28:06 -05:00
import PostList from "@components/post-list"
import { getCurrentUser } from "@lib/server/session"
import { authOptions } from "@lib/server/auth"
2022-12-04 04:31:51 -05:00
import { cache } from "react"
const cachedGetPostsByUser = cache(
async (userId: User["id"]) => await getPostsByUser(userId, true)
)
2022-11-11 19:33:43 -05:00
2022-11-10 02:11:36 -05:00
export default async function Mine() {
const userId = (await getCurrentUser())?.id
2022-11-10 02:11:36 -05:00
if (!userId) {
return redirect(authOptions.pages?.signIn || "/new")
2022-11-10 02:11:36 -05:00
}
2022-12-04 04:31:51 -05:00
const posts = await cachedGetPostsByUser(userId)
2022-11-10 02:11:36 -05:00
const hasMore = false
const stringifiedPosts = JSON.stringify(posts)
2022-11-18 01:36:53 -05:00
return (
<PostList
userId={userId}
morePosts={hasMore}
initialPosts={stringifiedPosts}
/>
)
2022-11-10 02:11:36 -05:00
}