feat: support guest session (#919)

This commit is contained in:
Jeremy 2025-04-25 23:40:15 -07:00 committed by GitHub
parent 24cb2ce19b
commit 9279135355
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
34 changed files with 741 additions and 288 deletions

View file

@ -1,13 +1,13 @@
import { cookies } from 'next/headers';
import { notFound } from 'next/navigation';
import { notFound, redirect } from 'next/navigation';
import { auth } from '@/app/(auth)/auth';
import { Chat } from '@/components/chat';
import { getChatById, getMessagesByChatId } from '@/lib/db/queries';
import { DataStreamHandler } from '@/components/data-stream-handler';
import { DEFAULT_CHAT_MODEL } from '@/lib/ai/models';
import { DBMessage } from '@/lib/db/schema';
import { Attachment, UIMessage } from 'ai';
import type { DBMessage } from '@/lib/db/schema';
import type { Attachment, UIMessage } from 'ai';
export default async function Page(props: { params: Promise<{ id: string }> }) {
const params = await props.params;
@ -20,8 +20,12 @@ export default async function Page(props: { params: Promise<{ id: string }> }) {
const session = await auth();
if (!session) {
redirect('/api/auth/guest');
}
if (chat.visibility === 'private') {
if (!session || !session.user) {
if (!session.user) {
return notFound();
}
@ -59,6 +63,7 @@ export default async function Page(props: { params: Promise<{ id: string }> }) {
selectedChatModel={DEFAULT_CHAT_MODEL}
selectedVisibilityType={chat.visibility}
isReadonly={session?.user?.id !== chat.userId}
session={session}
/>
<DataStreamHandler id={id} />
</>
@ -73,6 +78,7 @@ export default async function Page(props: { params: Promise<{ id: string }> }) {
selectedChatModel={chatModelFromCookie.value}
selectedVisibilityType={chat.visibility}
isReadonly={session?.user?.id !== chat.userId}
session={session}
/>
<DataStreamHandler id={id} />
</>