From ee7dc00bffbedda4ba4fa90e6a2e88fdd57e2d04 Mon Sep 17 00:00:00 2001 From: Evorp <3vorpgaming@gmail.com> Date: Tue, 1 Oct 2024 16:33:36 -0700 Subject: [PATCH] fix auth again --- src/index.ts | 2 +- src/v2/tools/authentication.ts | 2 +- src/v2/tools/handleError.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 337d87b..b438478 100644 --- a/src/index.ts +++ b/src/index.ts @@ -81,7 +81,7 @@ app.use((err: unknown, req: Request, res: Response, next: NextFunction) => { if (!err) return next(); // logs and handles errors - const apiError = handleError(err, req.path); + const apiError = handleError(err, req.path, req.method); if (err instanceof ValidateError) { res .status(422) diff --git a/src/v2/tools/authentication.ts b/src/v2/tools/authentication.ts index 1f90296..1da3842 100644 --- a/src/v2/tools/authentication.ts +++ b/src/v2/tools/authentication.ts @@ -89,7 +89,7 @@ export async function expressAuthentication( } // check add-on ownership - if (scopes.includes("addon:own")) { + if (scopes.includes("addon:own") || scopes.includes("addon:approved")) { const idOrSlug = request.params.id_or_slug; if (isSlug(idOrSlug)) { const addon: Addon = (await addonService.getAddonFromSlugOrId(idOrSlug))[1]; diff --git a/src/v2/tools/handleError.ts b/src/v2/tools/handleError.ts index a5012fd..ddeac9b 100644 --- a/src/v2/tools/handleError.ts +++ b/src/v2/tools/handleError.ts @@ -7,7 +7,7 @@ import { APIError } from "./errors"; * @param err error to handle * @returns front-end API error to show user */ -export default function handleError(err: any, route: string): APIError { +export default function handleError(err: any, route: string, method: string): APIError { const code = Number( (typeof err.status === "number" ? err.status : err.statusCode) || @@ -21,7 +21,7 @@ export default function handleError(err: any, route: string): APIError { let printed = false; if (process.env.VERBOSE === "true") { - console.error(`[${new Date().toUTCString()}] ${route}`); + console.error(`[${new Date().toUTCString()}] ${method} ${route}`); // if the message already includes a stack don't print it twice if (message?.stack) console.error(`(${code})`, message); else console.error(`(${code})`, message, "\n", stack);