Add authenticated login and SSO protection
This commit is contained in:
@@ -5,9 +5,10 @@ export function jsonOk<T>(payload: T, init?: ResponseInit) {
|
||||
}
|
||||
|
||||
export function jsonError(error: unknown, status = 400) {
|
||||
const resolvedStatus = statusFromError(error) || status;
|
||||
return NextResponse.json({
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
}, { status });
|
||||
}, { status: resolvedStatus });
|
||||
}
|
||||
|
||||
export async function readJsonBody<T extends Record<string, unknown>>(request: Request): Promise<T> {
|
||||
@@ -17,3 +18,9 @@ export async function readJsonBody<T extends Record<string, unknown>>(request: R
|
||||
return {} as T;
|
||||
}
|
||||
}
|
||||
|
||||
function statusFromError(error: unknown): number | undefined {
|
||||
if (typeof error !== "object" || error === null || !("status" in error)) return undefined;
|
||||
const status = Number((error as { status?: unknown }).status);
|
||||
return Number.isInteger(status) && status >= 400 && status <= 599 ? status : undefined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user