From 642e141abd503076a11be00f2b11af5f34e04b8e Mon Sep 17 00:00:00 2001 From: Philipp Dormann Date: Wed, 11 Dec 2024 18:16:29 +0100 Subject: [PATCH] AUTHKEY --- .env.example | 3 ++- src/index.ts | 4 ++++ src/routes/email.ts | 5 +++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index b6e66f4..1030b5b 100644 --- a/.env.example +++ b/.env.example @@ -5,4 +5,5 @@ SMTP_PASS="secret.1" EMAIL_FROM="noreply@lauf-fuer-kaya.de" EMAIL_REPLYTO="info@lauf-fuer-kaya.de" REDIS_URL=redis://localhost:6379 -FRONTEND_URL="https://run.lauf-fuer-kaya.de" \ No newline at end of file +FRONTEND_URL="https://run.lauf-fuer-kaya.de" +AUTHKEY="" \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 6e405f9..af629b3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,6 +9,10 @@ const app = new Hono() app.use('*', logger()) app.use('*', prettyJSON()) +if ((process.env.AUTHKEY || "") === "") { + console.warn("process.env.AUTHKEY was not provided!"); +} + app.route('/api/v1/email', emailRouter) app.get('/docs', createSwaggerUI()) app.get('/swagger', createSwaggerUI()) diff --git a/src/routes/email.ts b/src/routes/email.ts index 2778461..c252e57 100644 --- a/src/routes/email.ts +++ b/src/routes/email.ts @@ -1,4 +1,5 @@ import { Hono } from 'hono' +import { bearerAuth } from 'hono/bearer-auth' import { zValidator } from '@hono/zod-validator' import { z } from 'zod' import { EmailService } from '../services/email' @@ -32,7 +33,7 @@ async function generateBarcodeDataURL(data) { return dataURL; } -emailRouter.post('/', zValidator('json', sendEmailSchema), async (c) => { +emailRouter.post('/', bearerAuth({ token: process.env.AUTHKEY }),zValidator('json', sendEmailSchema), async (c) => { let { to, templateName, language, data } = c.req.valid('json') try { @@ -67,7 +68,7 @@ emailRouter.post('/', zValidator('json', sendEmailSchema), async (c) => { }) // Add queue status endpoint -emailRouter.get('/status', async (c) => { +emailRouter.get('/status', bearerAuth({ token: process.env.AUTHKEY }),async (c) => { try { const status = await emailService.getQueueStatus() return c.json(status)