Add authenticated login and SSO protection

This commit is contained in:
inman
2026-05-29 15:54:13 +08:00
parent e36f28a668
commit 0648874801
50 changed files with 1853 additions and 63 deletions

View File

@@ -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;
}