-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDocuments.tsx
45 lines (38 loc) · 1.11 KB
/
Documents.tsx
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
42
43
44
45
import { auth } from "@clerk/nextjs/server";
import { Timestamp } from "firebase-admin/firestore";
import { adminDb } from "@/firebaseAdmin";
import Document from "./Document";
import { TableRow } from "./ui/table";
async function Documents() {
await auth.protect();
const { userId } = await auth();
if (!userId) {
throw new Error("User not found");
}
const documentsSnapshot = await adminDb
.collection("users")
.doc(userId)
.collection("files")
.get();
return (
<>
{documentsSnapshot.docs.map((doc) => {
const { name, downloadUrl, size, createdAt } = doc.data();
const createdAtDate = createdAt instanceof Timestamp ? createdAt.toDate() : new Date(createdAt);
return (
<TableRow key={doc.id} className="cursor-pointer">
<Document
id={doc.id}
name={name}
size={size}
downloadUrl={downloadUrl}
createdAt={createdAtDate.toLocaleString()}
/>
</TableRow>
);
})}
{/* <PlaceholderDocument /> */}
</>
);
}
export default Documents;