From 368e6eb0fa83115ffeaf8d2105644ce65363184c Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Sat, 23 Apr 2022 02:05:56 +0200 Subject: [PATCH] fix: rename dateInPast -> dateNotInPast --- lib/helpers/verifyApiKey.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/helpers/verifyApiKey.ts b/lib/helpers/verifyApiKey.ts index 77eaf7e4cb..6a8c24df4e 100644 --- a/lib/helpers/verifyApiKey.ts +++ b/lib/helpers/verifyApiKey.ts @@ -12,7 +12,7 @@ declare module "next" { } // Used to check if the API key is not expired, could be extracted if reused. but not for now. -export const dateInPast = function (date: Date) { +export const dateNotInPast = function (date: Date) { const now = new Date(); if (now.setHours(0, 0, 0, 0) <= date.setHours(0, 0, 0, 0)) { return true; @@ -30,7 +30,7 @@ export const verifyApiKey: NextMiddleware = async (req, res, next) => { const apiKey = await prisma.apiKey.findUnique({ where: { hashedKey } }); // If we cannot find any api key. Throw a 401 Unauthorized. if (!apiKey) return res.status(401).json({ error: "Your api key is not valid" }); - if (apiKey.expiresAt && dateInPast(apiKey.expiresAt)) { + if (apiKey.expiresAt && dateNotInPast(apiKey.expiresAt)) { return res.status(401).json({ error: "This api key is expired" }); } if (!apiKey.userId) return res.status(404).json({ error: "No user found for this api key" });