-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.tsx
More file actions
41 lines (38 loc) · 1.04 KB
/
template.tsx
File metadata and controls
41 lines (38 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { getLogtoContext } from '@logto/next/server-actions';
import type * as React from 'react';
import {
SidebarInset,
SidebarProvider,
SidebarTrigger,
} from '@/components/animate-ui/radix/sidebar';
import { ChatSidebar } from '@/components/sidebar';
import { logtoConfig } from '@/lib/auth';
import { prisma } from '@/lib/prisma';
export default async function ChatLayout({
children,
}: {
children: React.ReactNode;
}) {
const { claims } = await getLogtoContext(logtoConfig);
const chats = await prisma.chat.findMany({
where: { userId: claims?.sub || '' },
});
const data = {
user: {
name: claims?.name || '...',
id: claims?.sub || '...',
avatar: claims?.picture || '/default-avatar.png',
},
chats: chats.map((chat) => ({
name: chat.name || 'Untitled Chat',
id: chat.id,
})),
};
return (
<SidebarProvider>
<ChatSidebar data={data} />
<SidebarTrigger className={'mt-3 ml-3 hover:bg-secondary'} />
<SidebarInset>{children}</SidebarInset>
</SidebarProvider>
);
}