feat: support guest session (#919)
This commit is contained in:
parent
24cb2ce19b
commit
9279135355
34 changed files with 741 additions and 288 deletions
|
|
@ -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} />
|
||||
</>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue