Added basic validation for requests
This commit is contained in:
@@ -6,7 +6,7 @@ export async function GET(req: Request) {
|
||||
try {
|
||||
const user = await fetchUser(req)
|
||||
if (!user || user.role != "ADMIN") {
|
||||
return new NextResponse("Unauthorized", { status: 401 });
|
||||
return NextResponse.json({ message: 'Unauthorized.', error: null, value: null }, { status: 401 });
|
||||
}
|
||||
|
||||
const impersonation = await db.impersonation.findFirst({
|
||||
@@ -18,7 +18,7 @@ export async function GET(req: Request) {
|
||||
return NextResponse.json(impersonation);
|
||||
} catch (error) {
|
||||
console.log("[AUTH/ACCOUNT/IMPERSONATION]", error);
|
||||
return new NextResponse("Internal Error", { status: 500 });
|
||||
return NextResponse.json({ message: 'Something went wrong', error: error, value: null }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ export async function POST(req: Request) {
|
||||
try {
|
||||
const user = await fetchUser(req)
|
||||
if (!user || user.role != "ADMIN") {
|
||||
return new NextResponse("Unauthorized", { status: 401 });
|
||||
return NextResponse.json({ message: 'Unauthorized.', error: null, value: null }, { status: 401 });
|
||||
}
|
||||
|
||||
const { targetId } = await req.json();
|
||||
@@ -41,7 +41,7 @@ export async function POST(req: Request) {
|
||||
return NextResponse.json(impersonation);
|
||||
} catch (error) {
|
||||
console.log("[AUTH/ACCOUNT/IMPERSONATION]", error);
|
||||
return new NextResponse("Internal Error", { status: 500 });
|
||||
return NextResponse.json({ message: 'Something went wrong', error: error, value: null }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ export async function PUT(req: Request) {
|
||||
try {
|
||||
const user = await fetchUser(req)
|
||||
if (!user || user.role != "ADMIN") {
|
||||
return new NextResponse("Unauthorized", { status: 401 });
|
||||
return NextResponse.json({ message: 'Unauthorized.', error: null, value: null }, { status: 401 });
|
||||
}
|
||||
|
||||
const { targetId } = await req.json();
|
||||
@@ -66,7 +66,7 @@ export async function PUT(req: Request) {
|
||||
return NextResponse.json(impersonation);
|
||||
} catch (error) {
|
||||
console.log("[AUTH/ACCOUNT/IMPERSONATION]", error);
|
||||
return new NextResponse("Internal Error", { status: 500 });
|
||||
return NextResponse.json({ message: 'Something went wrong', error: error, value: null }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ export async function DELETE(req: Request) {
|
||||
try {
|
||||
const user = await fetchUser(req)
|
||||
if (!user || user.role != "ADMIN") {
|
||||
return new NextResponse("Unauthorized", { status: 401 });
|
||||
return NextResponse.json({ message: 'Unauthorized.', error: null, value: null }, { status: 401 });
|
||||
}
|
||||
|
||||
const impersonation = await db.impersonation.delete({
|
||||
@@ -86,6 +86,6 @@ export async function DELETE(req: Request) {
|
||||
return NextResponse.json(impersonation)
|
||||
} catch (error) {
|
||||
console.log("[AUTH/ACCOUNT/IMPERSONATION]", error);
|
||||
return new NextResponse("Internal Error" + error, { status: 500 });
|
||||
return NextResponse.json({ message: 'Something went wrong.', error: null, value: null }, { status: 500 })
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user