From 1aeaf8fd4752e8764120569136d378efaa1b1209 Mon Sep 17 00:00:00 2001 From: Lucemans Date: Sun, 29 May 2022 23:41:41 +0200 Subject: [PATCH] Introduce backwards-compatibility for API Keys --- src/routes/protected/create.ts | 4 ++-- src/util/http/useAPIToken.ts | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/routes/protected/create.ts b/src/routes/protected/create.ts index 27469c2f..071d32a6 100644 --- a/src/routes/protected/create.ts +++ b/src/routes/protected/create.ts @@ -8,7 +8,7 @@ import { Extract } from 'unzipper'; import { StorageBackend } from '../..'; import { DB } from '../../database'; -import { useAuth } from '../../util/http/useAuth'; +import { useAPIToken } from '../../util/http/useAPIToken'; import { log } from '../../util/logging'; import { startAction } from '../../util/sentry/createChild'; import { sentryHandle } from '../../util/sentry/sentryHandle'; @@ -59,7 +59,7 @@ export const CreateRoute: FastifyPluginAsync = async (router, options) => { (request, reply) => { handle(request, reply, async (transaction, registerCleanup) => { // Check auth - const auth = await useAuth(request, reply); + const auth = await useAPIToken(request, reply); if (typeof auth !== 'string') { return auth; diff --git a/src/util/http/useAPIToken.ts b/src/util/http/useAPIToken.ts index b4de7323..0d2f5c7c 100644 --- a/src/util/http/useAPIToken.ts +++ b/src/util/http/useAPIToken.ts @@ -50,6 +50,8 @@ export const useAPIToken: ( owner_id: decoded.account, }); + console.log(decoded.account, decoded.value.toString()); + if (!key) return { status: 403, logMessages: ['Not owner of Site'] }; request.context['user'] = {