From 41d27efbb5d75285838435caf862825d6e43c2ea Mon Sep 17 00:00:00 2001 From: Bram Adams <3282661+bramses@users.noreply.github.com> Date: Sat, 24 Aug 2024 02:52:45 -0400 Subject: [PATCH] feat: Add API_KEY to fetch and list routes for authentication --- src/app/[locale]/(auth)/api/daily/route.ts | 3 ++- src/app/[locale]/(auth)/api/fetch/route.ts | 11 ++++++++++- src/app/[locale]/(auth)/api/list/route.ts | 3 ++- src/app/[locale]/(auth)/api/random/route.ts | 3 ++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/app/[locale]/(auth)/api/daily/route.ts b/src/app/[locale]/(auth)/api/daily/route.ts index 1736ea9..b16d84f 100644 --- a/src/app/[locale]/(auth)/api/daily/route.ts +++ b/src/app/[locale]/(auth)/api/daily/route.ts @@ -14,7 +14,7 @@ export const POST = async (request: Request) => { if (!dbRes) { return NextResponse.json({}, { status: 500 }); } - const { DATABASE_URL } = await dbRes.json(); + const { DATABASE_URL, API_KEY } = await dbRes.json(); const resp = await fetch(`${CLOUD_URL}/entriesByDate`, { method: 'POST', @@ -25,6 +25,7 @@ export const POST = async (request: Request) => { excludeParentId: true, date, dbPath: DATABASE_URL, + apiKey: API_KEY, }), }); logger.info('resp:', resp); diff --git a/src/app/[locale]/(auth)/api/fetch/route.ts b/src/app/[locale]/(auth)/api/fetch/route.ts index 8276123..6929600 100644 --- a/src/app/[locale]/(auth)/api/fetch/route.ts +++ b/src/app/[locale]/(auth)/api/fetch/route.ts @@ -2,11 +2,19 @@ import { NextResponse } from 'next/server'; import { logger } from '@/libs/Logger'; +import { GET } from '../getCBPath/route'; + // import env variables export const POST = async (request: Request) => { const { id } = await request.json(); - const { CLOUD_URL, DATABASE_URL } = process.env; + const { CLOUD_URL } = process.env; + + const dbRes = await GET(request); + if (!dbRes) { + return NextResponse.json({}, { status: 500 }); + } + const { DATABASE_URL, API_KEY } = await dbRes.json(); const resp = await fetch(`${CLOUD_URL}/fetch`, { method: 'POST', @@ -16,6 +24,7 @@ export const POST = async (request: Request) => { body: JSON.stringify({ id: id.toString(), dbPath: DATABASE_URL, + apiKey: API_KEY, }), }); logger.info('resp:', resp); diff --git a/src/app/[locale]/(auth)/api/list/route.ts b/src/app/[locale]/(auth)/api/list/route.ts index 13fe891..45e025c 100644 --- a/src/app/[locale]/(auth)/api/list/route.ts +++ b/src/app/[locale]/(auth)/api/list/route.ts @@ -14,7 +14,7 @@ export const POST = async (request: Request) => { if (!dbRes) { return NextResponse.json({}, { status: 500 }); } - const { DATABASE_URL } = await dbRes.json(); + const { DATABASE_URL, API_KEY } = await dbRes.json(); const resp = await fetch(`${CLOUD_URL}/list`, { method: 'POST', @@ -27,6 +27,7 @@ export const POST = async (request: Request) => { sortModel, filterModel, dbPath: DATABASE_URL, + apiKey: API_KEY, }), }); logger.info('resp:', resp); diff --git a/src/app/[locale]/(auth)/api/random/route.ts b/src/app/[locale]/(auth)/api/random/route.ts index e6d4707..eb1c971 100644 --- a/src/app/[locale]/(auth)/api/random/route.ts +++ b/src/app/[locale]/(auth)/api/random/route.ts @@ -13,7 +13,7 @@ export const POST = async (request: Request) => { if (!dbRes) { return NextResponse.json({}, { status: 500 }); } - const { DATABASE_URL } = await dbRes.json(); + const { DATABASE_URL, API_KEY } = await dbRes.json(); const resp = await fetch(`${CLOUD_URL}/random`, { method: 'POST', @@ -22,6 +22,7 @@ export const POST = async (request: Request) => { }, body: JSON.stringify({ dbPath: DATABASE_URL, + apiKey: API_KEY, }), }); logger.info('resp:', resp);