import { sessionUser } from '@/auth'; import { Card } from '../ui/Card'; import { IconExclamationTriangle } from '../ui/Icons'; import Link from 'next/link'; import { ChatWithMessages } from '@/lib/types'; import { dbGetUser } from '@/lib/db/functions'; import Avatar from '../Avatar'; export interface TopPrompt { chat: ChatWithMessages; userId?: string | null; } export default async function TopPrompt({ chat, userId }: TopPrompt) { const authorId = chat.userId; console.log('[Ming] ~ TopPrompt ~ authorId:', authorId); // 1. Viewer logged in, Viewer = Author if (userId && authorId === userId) { return null; } // 2. Viewer logged in, No Author if (userId && !authorId) { return null; } // 3. Author, but is not Viewer if (authorId && authorId !== userId) { const chatAuthor = authorId ? await dbGetUser(authorId) : null; return ( Code author:{' '} {chatAuthor?.name ?? 'Unknown'} ); } // 4. No author, Viewer not logged in if (!userId && !authorId) { return ( Sign in {' '} to save and revisit your chat history! ); } return null; }
Code author:{' '} {chatAuthor?.name ?? 'Unknown'}
Sign in {' '} to save and revisit your chat history!