Added basic validation for requests
This commit is contained in:
@@ -6,7 +6,7 @@ export async function GET(req: Request, { params } : { params: { id: string } })
|
||||
try {
|
||||
const user = await fetchUserWithImpersonation(req)
|
||||
if (!user) {
|
||||
return new NextResponse("Unauthorized", { status: 401 });
|
||||
return NextResponse.json({ message: 'Unauthorized.', error: null, value: null }, { status: 401 });
|
||||
}
|
||||
|
||||
let id = req.headers?.get('x-api-key')
|
||||
@@ -23,7 +23,7 @@ export async function GET(req: Request, { params } : { params: { id: string } })
|
||||
return NextResponse.json(tokens);
|
||||
} catch (error) {
|
||||
console.log("[TOKEN/GET]", error);
|
||||
return new NextResponse("Internal Error", { status: 500 });
|
||||
return NextResponse.json({ message: 'Something went wrong', error: error, value: null }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ export async function DELETE(req: Request, { params } : { params: { id: string }
|
||||
try {
|
||||
const user = await fetchUserWithImpersonation(req)
|
||||
if (!user) {
|
||||
return new NextResponse("Unauthorized", { status: 401 });
|
||||
return NextResponse.json({ message: 'Unauthorized.', error: null, value: null }, { status: 401 });
|
||||
}
|
||||
|
||||
const { id } = params
|
||||
@@ -45,6 +45,6 @@ export async function DELETE(req: Request, { params } : { params: { id: string }
|
||||
return NextResponse.json(token);
|
||||
} catch (error) {
|
||||
console.log("[TOKEN/DELETE]", error);
|
||||
return new NextResponse("Internal Error", { status: 500 });
|
||||
return NextResponse.json({ message: 'Something went wrong', error: error, value: null }, { status: 500 })
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ export async function GET(req: Request) {
|
||||
try {
|
||||
const user = await fetchUserWithImpersonation(req);
|
||||
if (!user) {
|
||||
return new NextResponse("Unauthorized", { status: 401 });
|
||||
return NextResponse.json({ message: 'Unauthorized.', error: null, value: null }, { status: 401 });
|
||||
}
|
||||
|
||||
const api = await db.twitchConnection.findFirst({
|
||||
@@ -15,7 +15,7 @@ export async function GET(req: Request) {
|
||||
}
|
||||
})
|
||||
if (!api) {
|
||||
return new NextResponse("Forbidden", { status: 403 });
|
||||
return NextResponse.json({ message: 'You do not have permission for this.', error: null, value: null }, { status: 403 })
|
||||
}
|
||||
|
||||
const data = {
|
||||
@@ -28,6 +28,6 @@ export async function GET(req: Request) {
|
||||
return NextResponse.json(data);
|
||||
} catch (error) {
|
||||
console.log("[TOKENS/GET]", error);
|
||||
return new NextResponse("Internal Error", { status: 500 });
|
||||
return NextResponse.json({ message: 'Something went wrong', error: error, value: null }, { status: 500 })
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ export async function POST(req: Request) {
|
||||
try {
|
||||
const user = await fetchUserWithImpersonation(req)
|
||||
if (!user) {
|
||||
return new NextResponse("Unauthorized", { status: 401 });
|
||||
return NextResponse.json({ message: 'Unauthorized.', error: null, value: null }, { status: 401 });
|
||||
}
|
||||
|
||||
let { userId, label } = await req.json();
|
||||
@@ -29,8 +29,7 @@ export async function POST(req: Request) {
|
||||
|
||||
return NextResponse.json(token);
|
||||
} catch (error) {
|
||||
console.log("[TOKEN/POST]", error);
|
||||
return new NextResponse("Internal Error", { status: 500});
|
||||
return NextResponse.json({ message: 'Something went wrong.', error: error, value: null }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +37,7 @@ export async function DELETE(req: Request) {
|
||||
try {
|
||||
const user = await fetchUserWithImpersonation(req)
|
||||
if (!user) {
|
||||
return new NextResponse("Unauthorized", { status: 401 });
|
||||
return NextResponse.json({ message: 'Unauthorized.', error: null, value: null }, { status: 401 });
|
||||
}
|
||||
|
||||
const { id } = await req.json();
|
||||
@@ -55,8 +54,7 @@ export async function DELETE(req: Request) {
|
||||
|
||||
return NextResponse.json(token);
|
||||
} catch (error) {
|
||||
console.log("[TOKEN/DELETE]", error);
|
||||
return new NextResponse("Internal Error", { status: 500});
|
||||
return NextResponse.json({ message: 'Something went wrong.', error: error, value: null }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user