Added basic validation for requests

This commit is contained in:
Tom
2024-08-25 21:35:46 +00:00
parent 2d40d6fe09
commit 624b3fa63b
42 changed files with 608 additions and 492 deletions

View File

@ -9,7 +9,7 @@ export async function GET(req: Request) {
// Verify state against user id in user table.
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 connection = await db.twitchConnection.findFirst({
@ -18,7 +18,7 @@ export async function GET(req: Request) {
}
})
if (!connection) {
return new NextResponse("Forbidden", { status: 403 });
return NextResponse.json({ message: 'You do not have permission for this.', error: null, value: null }, { status: 403 })
}
try {
@ -59,7 +59,7 @@ export async function GET(req: Request) {
const { access_token, expires_in, refresh_token, token_type } = token
if (!access_token || !refresh_token || token_type !== "bearer") {
return new NextResponse("Unauthorized", { status: 401 });
return NextResponse.json({ message: 'Unauthorized.', error: null, value: null }, { status: 401 });
}
await db.twitchConnection.update({
@ -83,6 +83,6 @@ export async function GET(req: Request) {
return NextResponse.json(data)
} catch (error) {
console.log("[ACCOUNT]", error);
return new NextResponse("Internal Error", { status: 500 });
return NextResponse.json({ message: 'Something went wrong', error: error, value: null }, { status: 500 })
}
}