Skip to content

Commit

Permalink
feat: Add API_KEY to fetch and list routes for authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
bramses committed Aug 24, 2024
1 parent 165a1e0 commit 41d27ef
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/app/[locale]/(auth)/api/daily/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -25,6 +25,7 @@ export const POST = async (request: Request) => {
excludeParentId: true,
date,
dbPath: DATABASE_URL,
apiKey: API_KEY,
}),
});
logger.info('resp:', resp);
Expand Down
11 changes: 10 additions & 1 deletion src/app/[locale]/(auth)/api/fetch/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/app/[locale]/(auth)/api/list/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -27,6 +27,7 @@ export const POST = async (request: Request) => {
sortModel,
filterModel,
dbPath: DATABASE_URL,
apiKey: API_KEY,
}),
});
logger.info('resp:', resp);
Expand Down
3 changes: 2 additions & 1 deletion src/app/[locale]/(auth)/api/random/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -22,6 +22,7 @@ export const POST = async (request: Request) => {
},
body: JSON.stringify({
dbPath: DATABASE_URL,
apiKey: API_KEY,
}),
});
logger.info('resp:', resp);
Expand Down

0 comments on commit 41d27ef

Please sign in to comment.