Refactor to use ai/rsc (#253)
This commit is contained in:
parent
69ca8fcc22
commit
e85ba803dd
66 changed files with 2799 additions and 740 deletions
|
|
@ -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>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue