fix: actions

This commit is contained in:
shadcn 2023-06-16 21:52:01 +04:00
parent 071778533c
commit cb941daca9
17 changed files with 277 additions and 65 deletions

View file

@ -1,8 +1,9 @@
import { type Metadata } from 'next'
import { auth } from '@/auth'
import { notFound, redirect } from 'next/navigation'
import { Chat } from '@/components/chat'
import { auth } from '@/auth'
import { getChat } from '@/app/actions'
import { Chat } from '@/components/chat'
// export const runtime = 'edge'
export const preferredRegion = 'home'
@ -16,16 +17,30 @@ export interface ChatPageProps {
export async function generateMetadata({
params
}: ChatPageProps): Promise<Metadata> {
const { user } = await auth()
const chat = await getChat(params.id, user?.id ?? '')
const session = await auth()
if (!session?.user) {
return {}
}
const chat = await getChat(params.id, session.user.id)
return {
title: chat?.title.slice(0, 50) ?? 'Chat'
}
}
export default async function ChatPage({ params }: ChatPageProps) {
const { user } = await auth()
const chat = await getChat(params.id, user?.id ?? '')
const session = await auth()
if (!session?.user) {
redirect('/sign-in')
}
const chat = await getChat(params.id, session.user.id)
if (!chat) {
notFound()
}
return <Chat id={chat.id} initialMessages={chat.messages} />
}