🔒️ Fix middleware logic

This commit is contained in:
Luke Vella 2025-06-01 10:59:12 +01:00
parent 532410d76c
commit b9cbb61afc
No known key found for this signature in database
GPG key ID: 469CAD687F0D784C

View file

@ -14,7 +14,6 @@ import { kv } from "@vercel/kv";
import { Hono } from "hono"; import { Hono } from "hono";
import { rateLimiter } from "hono-rate-limiter"; import { rateLimiter } from "hono-rate-limiter";
import { bearerAuth } from "hono/bearer-auth"; import { bearerAuth } from "hono/bearer-auth";
import { some } from "hono/combine";
import { handle } from "hono/vercel"; import { handle } from "hono/vercel";
const isKvAvailable = const isKvAvailable =
@ -33,18 +32,16 @@ if (env.LICENSE_API_AUTH_TOKEN) {
app.post( app.post(
"/licenses", "/licenses",
zValidator("json", createLicenseInputSchema), zValidator("json", createLicenseInputSchema),
some( rateLimiter({
bearerAuth({ token: env.LICENSE_API_AUTH_TOKEN }), windowMs: 60 * 60 * 1000,
rateLimiter({ limit: 10,
windowMs: 60 * 60 * 1000, store: isKvAvailable
limit: 10, ? new RedisStore({
store: isKvAvailable client: kv,
? new RedisStore({ })
client: kv, : undefined,
}) }),
: undefined, bearerAuth({ token: env.LICENSE_API_AUTH_TOKEN }),
}),
),
async (c) => { async (c) => {
const { type, seats, expiresAt, licenseeEmail, licenseeName, version } = const { type, seats, expiresAt, licenseeEmail, licenseeName, version } =
c.req.valid("json"); c.req.valid("json");