BREAKING CHANGE(opsserver): Require authentication for OpsServer endpoints, split handlers into authenticated view/admin routers, and make identity required on many TypedRequest interfaces

This commit is contained in:
2026-03-03 21:39:20 +00:00
parent baab152fd3
commit ed3964e892
27 changed files with 326 additions and 227 deletions

View File

@@ -22,16 +22,17 @@ export async function passGuards<T extends { identity?: any }>(
}
/**
* Helper to check admin identity in handlers
* Helper to check admin identity in handlers and middleware.
* Accepts both optional and required identity for flexibility.
*/
export async function requireAdminIdentity<T extends { identity?: interfaces.data.IIdentity }>(
export async function requireAdminIdentity(
adminHandler: AdminHandler,
dataArg: T
dataArg: { identity?: interfaces.data.IIdentity }
): Promise<void> {
if (!dataArg.identity) {
throw new plugins.typedrequest.TypedResponseError('No identity provided');
}
const passed = await adminHandler.adminIdentityGuard.exec({ identity: dataArg.identity });
if (!passed) {
throw new plugins.typedrequest.TypedResponseError('Admin access required');
@@ -39,16 +40,17 @@ export async function requireAdminIdentity<T extends { identity?: interfaces.dat
}
/**
* Helper to check valid identity in handlers
* Helper to check valid identity in handlers and middleware.
* Accepts both optional and required identity for flexibility.
*/
export async function requireValidIdentity<T extends { identity?: interfaces.data.IIdentity }>(
export async function requireValidIdentity(
adminHandler: AdminHandler,
dataArg: T
dataArg: { identity?: interfaces.data.IIdentity }
): Promise<void> {
if (!dataArg.identity) {
throw new plugins.typedrequest.TypedResponseError('No identity provided');
}
const passed = await adminHandler.validIdentityGuard.exec({ identity: dataArg.identity });
if (!passed) {
throw new plugins.typedrequest.TypedResponseError('Valid identity required');