forked from rahulsainlll/git-trace
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
318b9d3
commit c90000b
Showing
5 changed files
with
112 additions
and
100 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,78 @@ | ||
// // post : | ||
// // Checks if the request method is POST. | ||
// // Retrieves the user’s ID using Clerk’s getAuth function. | ||
// // Creates a new bookmark associated with the logged-in user using Prisma’s create method. | ||
// // Returns the created bookmark or an error if something goes wrong. | ||
import { NextResponse } from "next/server"; | ||
import prisma from "@/lib/prisma"; | ||
import { getServerSession } from "next-auth/next"; | ||
import { authOptions } from "../auth/[...nextauth]/route"; | ||
|
||
// import { NextResponse } from "next/server"; | ||
// import prisma from "@/lib/prisma"; | ||
// import { auth } from "@clerk/nextjs/server"; | ||
export async function GET(req: Request) { | ||
const session = await getServerSession(authOptions); | ||
|
||
// export async function GET(req: Request) { | ||
// const { userId } = auth(); | ||
if (!session?.user?.email) { | ||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); | ||
} | ||
|
||
// if (!userId) { | ||
// return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); | ||
// } | ||
try { | ||
const user = await prisma.user.findUnique({ | ||
where: { email: session.user.email }, | ||
}); | ||
|
||
// try { | ||
// const bookmarks = await prisma.bookmark.findMany({ | ||
// where: { userId }, | ||
// }); | ||
// return NextResponse.json(bookmarks); | ||
// } catch (error) { | ||
// return NextResponse.json( | ||
// { error: "Failed to fetch bookmarks" }, | ||
// { status: 500 } | ||
// ); | ||
// } | ||
// } | ||
if (!user) { | ||
return NextResponse.json({ error: "User not found" }, { status: 404 }); | ||
} | ||
|
||
// export async function POST(req: Request) { | ||
// const { userId } = auth(); | ||
const bookmarks = await prisma.bookmark.findMany({ | ||
where: { userId: user.id }, | ||
}); | ||
|
||
// if (!userId) { | ||
// return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); | ||
// } | ||
return NextResponse.json(bookmarks); | ||
} catch (error) { | ||
return NextResponse.json( | ||
{ error: "Failed to fetch bookmarks" }, | ||
{ status: 500 } | ||
); | ||
} | ||
} | ||
|
||
// try { | ||
// // Check if the user exists | ||
// const userExists = await prisma.user.findUnique({ | ||
// where: { id: userId }, | ||
// }); | ||
export async function POST(req: Request) { | ||
const session = await getServerSession(authOptions); | ||
|
||
// if (!userExists) { | ||
// return NextResponse.json( | ||
// { error: "User does not exist" }, | ||
// { status: 404 } | ||
// ); | ||
// } | ||
if (!session?.user?.email) { | ||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); | ||
} | ||
|
||
// const body = await req.json(); | ||
// const { name, url, description } = body; | ||
try { | ||
const user = await prisma.user.findUnique({ | ||
where: { email: session.user.email }, | ||
}); | ||
|
||
// if (!name || !url) { | ||
// return NextResponse.json( | ||
// { error: "Name and URL are required" }, | ||
// { status: 400 } | ||
// ); | ||
// } | ||
if (!user) { | ||
return NextResponse.json({ error: "User not found" }, { status: 404 }); | ||
} | ||
|
||
// const bookmark = await prisma.bookmark.create({ | ||
// data: { | ||
// name, | ||
// url, | ||
// description: description || null, | ||
// userId, | ||
// }, | ||
// }); | ||
const body = await req.json(); | ||
const { name, url, description } = body; | ||
|
||
// return NextResponse.json(bookmark, { status: 201 }); | ||
// } catch (error) { | ||
// console.error("Failed to create bookmark:", error); // Added logging for better debugging | ||
// return NextResponse.json( | ||
// { error: "Failed to create bookmark" }, | ||
// { status: 500 } | ||
// ); | ||
// } | ||
// } | ||
if (!name || !url) { | ||
return NextResponse.json( | ||
{ error: "Name and URL are required" }, | ||
{ status: 400 } | ||
); | ||
} | ||
|
||
const bookmark = await prisma.bookmark.create({ | ||
data: { | ||
name, | ||
url, | ||
description: description || null, | ||
userId: user.id, | ||
}, | ||
}); | ||
|
||
return NextResponse.json(bookmark, { status: 201 }); | ||
} catch (error) { | ||
console.error("Failed to create bookmark:", error); | ||
return NextResponse.json( | ||
{ error: "Failed to create bookmark" }, | ||
{ status: 500 } | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import NextAuth from "next-auth"; | ||
|
||
declare module "next-auth" { | ||
interface Session { | ||
user: { | ||
id: string; | ||
name?: string | null; | ||
email?: string | null; | ||
image?: string | null; | ||
}; | ||
} | ||
|
||
interface User { | ||
id: string; | ||
} | ||
} |