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