@@ -12,10 +12,11 @@ import { type NextRequest, NextResponse } from 'next/server';
1212 *
1313 * Body:
1414 * - userId: string - The ID of the user to delete.
15+ * - email: string - The email of the user to delete.
1516 *
1617 * Returns:
1718 * - 200: { success: true, message: "User deleted successfully", userId: string }
18- * - 400: { success: false, error: "Missing userId in request body" }
19+ * - 400: { success: false, error: "Missing userId or email in request body" }
1920 * - 401: { success: false, error: "Unauthorized" }
2021 * - 500: { success: false, error: "Failed to delete user" }
2122 */
@@ -59,22 +60,25 @@ export async function POST(request: NextRequest) {
5960 ) ;
6061 }
6162
62- const { userId } = body ;
63+ const { userId, email } = body ;
6364
64- if ( ! userId ) {
65+ if ( ! userId || ! email ) {
6566 return NextResponse . json (
6667 {
6768 success : false ,
68- error : 'Missing userId in request body' ,
69+ error : 'Missing userId or email in request body' ,
6970 } ,
7071 { status : 400 } ,
7172 ) ;
7273 }
7374
7475 try {
75- // Check if user exists
76+ // Check if user exists with matching id and email
7677 const existingUser = await db . user . findUnique ( {
77- where : { id : userId } ,
78+ where : {
79+ id : userId ,
80+ email : email ,
81+ } ,
7882 } ) ;
7983
8084 if ( ! existingUser ) {
@@ -89,7 +93,10 @@ export async function POST(request: NextRequest) {
8993
9094 // Delete the user (cascading deletes will handle related records)
9195 await db . user . delete ( {
92- where : { id : userId } ,
96+ where : {
97+ id : userId ,
98+ email : email ,
99+ } ,
93100 } ) ;
94101
95102 console . log ( `QA: User ${ userId } deleted successfully` ) ;
0 commit comments