diff --git a/app/api/auth/[...nextauth]/route.ts b/app/api/auth/[...nextauth]/route.ts index 70f1bd1..42d28b4 100644 --- a/app/api/auth/[...nextauth]/route.ts +++ b/app/api/auth/[...nextauth]/route.ts @@ -1,18 +1,32 @@ -import NextAuth from "next-auth"; +import NextAuth, { Session, AuthOptions } from "next-auth"; import GoogleProvider from "next-auth/providers/google"; import { PrismaAdapter } from "@next-auth/prisma-adapter"; import prisma from "@/lib/db"; +import { JWT } from "next-auth/jwt"; -const handler = NextAuth({ - providers:[ +export const authOption: AuthOptions = { + providers: [ GoogleProvider({ - clientId: process.env.GOOGLE_CLIENT_ID!, - clientSecret: process.env.GOOGLE_CLIENT_SECRET! - }) + clientId: process.env.GOOGLE_CLIENT_ID!, + clientSecret: process.env.GOOGLE_CLIENT_SECRET!, + }), ], secret: process.env.NEXTAUTH_SECRET!, - session:{strategy: "jwt"}, + session: { + strategy: "jwt", // This ensures TypeScript recognizes this as a valid strategy + }, adapter: PrismaAdapter(prisma), -}) + callbacks: { + session: async ({ session, token }: { session: Session; token: JWT }) => { + if (token && session.user) { + session.user.id = token.sub; + session.user.email = token.email; + } + return session; + }, + }, +}; -export { handler as GET, handler as POST } \ No newline at end of file +const handler = NextAuth(authOption); + +export { handler as GET, handler as POST, handler as OPTIONS }; diff --git a/app/document/[documentId]/page.tsx b/app/document/[documentId]/page.tsx new file mode 100644 index 0000000..bab0e04 --- /dev/null +++ b/app/document/[documentId]/page.tsx @@ -0,0 +1,12 @@ +import Document from '@/components/Document' +import React from 'react' + +const Page = ({params : {documentId}} : {params:{documentId: string}}) => { + return ( +
+ +
+ ) +} + +export default Page diff --git a/components/AddDocument.tsx b/components/AddDocument.tsx index c96148e..19ece7a 100644 --- a/components/AddDocument.tsx +++ b/components/AddDocument.tsx @@ -57,9 +57,9 @@ const AddDocument = ({ categoryId }: { categoryId: string }) => { diff --git a/components/Category.tsx b/components/Category.tsx index 8b13c01..e2947bf 100644 --- a/components/Category.tsx +++ b/components/Category.tsx @@ -2,28 +2,42 @@ import React from 'react' import prisma from '@/lib/db' import { Separator } from "@/components/ui/separator" import AddDocument from './AddDocument' +import DocumentGroup from './DocumentGroup' const getDocumentsOfCategory = async(id : string)=>{ -return await prisma.category.findFirst({where: {id: id}, include: {documents: true,}}) +return await prisma.category.findFirst({where: {id: id}, include: {documents: {include: {user: {select: {email: true, image: true}}}}}}) } const Category = async ({categoryId}: {categoryId : string}) => { const result = await getDocumentsOfCategory(categoryId) + console.log(result) const count = result?.documents.length return ( -
-

+

+
+
+

{result?.name}

+
+ +
+
+ -{ count === 0 && + +
+
+

{count === 0 && "No document find. Click on the button to add."}

+
- + {result && + + }
-}
) diff --git a/components/Document.tsx b/components/Document.tsx new file mode 100644 index 0000000..8192091 --- /dev/null +++ b/components/Document.tsx @@ -0,0 +1,18 @@ +import prisma from '@/lib/db' +import React from 'react' + +const getDocument = async(id: string)=>{ +return await prisma.document.findFirst({where: {id: id}}) +} +const Document = async ({documentId}: {documentId: string}) => { + + const result = await getDocument(documentId) + + return ( +
+