Check session user id before performing action (#391)
This commit is contained in:
parent
c2757f87f9
commit
b38c49da59
3 changed files with 62 additions and 36 deletions
|
|
@ -2,6 +2,7 @@ import { clearChats, getChats } from '@/app/actions'
|
|||
import { ClearHistory } from '@/components/clear-history'
|
||||
import { SidebarItems } from '@/components/sidebar-items'
|
||||
import { ThemeToggle } from '@/components/theme-toggle'
|
||||
import { redirect } from 'next/navigation'
|
||||
import { cache } from 'react'
|
||||
|
||||
interface SidebarListProps {
|
||||
|
|
@ -16,23 +17,27 @@ const loadChats = cache(async (userId?: string) => {
|
|||
export async function SidebarList({ userId }: SidebarListProps) {
|
||||
const chats = await loadChats(userId)
|
||||
|
||||
return (
|
||||
<div className="flex flex-1 flex-col overflow-hidden">
|
||||
<div className="flex-1 overflow-auto">
|
||||
{chats?.length ? (
|
||||
<div className="space-y-2 px-2">
|
||||
<SidebarItems chats={chats} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="p-8 text-center">
|
||||
<p className="text-sm text-muted-foreground">No chat history</p>
|
||||
</div>
|
||||
)}
|
||||
if (!chats || 'error' in chats) {
|
||||
redirect('/')
|
||||
} else {
|
||||
return (
|
||||
<div className="flex flex-1 flex-col overflow-hidden">
|
||||
<div className="flex-1 overflow-auto">
|
||||
{chats?.length ? (
|
||||
<div className="space-y-2 px-2">
|
||||
<SidebarItems chats={chats} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="p-8 text-center">
|
||||
<p className="text-sm text-muted-foreground">No chat history</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center justify-between p-4">
|
||||
<ThemeToggle />
|
||||
<ClearHistory clearChats={clearChats} isEnabled={chats?.length > 0} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center justify-between p-4">
|
||||
<ThemeToggle />
|
||||
<ClearHistory clearChats={clearChats} isEnabled={chats?.length > 0} />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue