fix(auth): make things work

This commit is contained in:
Michael Zetterberg
2024-05-20 09:05:49 +02:00
parent c4912bbb94
commit 476e9f7582
19 changed files with 122 additions and 82 deletions

View File

@@ -1,42 +1,43 @@
import { NextResponse } from "next/server"
export function badRequest(body: unknown | string = "Bad request") {
export function badRequest(cause?: unknown) {
const resInit = {
status: 400,
statusText: "Bad request",
}
if (typeof body === "string") {
return new NextResponse(body, resInit)
}
return NextResponse.json(body, resInit)
return NextResponse.json(
{
cause,
},
resInit
)
}
export function notFound(body: unknown | string = "Not found") {
export function notFound(cause?: unknown) {
const resInit = {
status: 404,
statusText: "Not found",
}
if (typeof body === "string") {
return new NextResponse(body, resInit)
}
return NextResponse.json(body, resInit)
return NextResponse.json(
{
cause,
},
resInit
)
}
export function internalServerError(
body: unknown | string = "Internal Server Error"
) {
export function internalServerError(cause?: unknown) {
const resInit = {
status: 500,
statusText: "Internal Server Error",
}
if (typeof body === "string") {
return new NextResponse(body, resInit)
}
return NextResponse.json(body, resInit)
return NextResponse.json(
{
cause,
},
resInit
)
}