Refactor to use ai/rsc (#253)

This commit is contained in:
Jeremy 2024-03-14 20:00:52 +03:00 committed by GitHub
parent 69ca8fcc22
commit e85ba803dd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
66 changed files with 2799 additions and 740 deletions

View file

@ -2,8 +2,10 @@ import { type Metadata } from 'next'
import { notFound, redirect } from 'next/navigation'
import { auth } from '@/auth'
import { getChat } from '@/app/actions'
import { getChat, getMissingKeys } from '@/app/actions'
import { Chat } from '@/components/chat'
import { AI } from '@/lib/chat/actions'
import { Session } from '@/lib/types'
export interface ChatPageProps {
params: {
@ -27,21 +29,32 @@ export async function generateMetadata({
}
export default async function ChatPage({ params }: ChatPageProps) {
const session = await auth()
const session = (await auth()) as Session
const missingKeys = await getMissingKeys()
if (!session?.user) {
redirect(`/sign-in?next=/chat/${params.id}`)
redirect(`/login?next=/chat/${params.id}`)
}
const chat = await getChat(params.id, session.user.id)
const userId = session.user.id as string
const chat = await getChat(params.id, userId)
if (!chat) {
notFound()
redirect('/')
}
if (chat?.userId !== session?.user?.id) {
notFound()
}
return <Chat id={chat.id} initialMessages={chat.messages} />
return (
<AI initialAIState={{ chatId: chat.id, messages: chat.messages }}>
<Chat
id={chat.id}
session={session}
initialMessages={chat.messages}
missingKeys={missingKeys}
/>
</AI>
)
}