fix: rename dateInPast -> dateNotInPast

pull/9078/head
Agusti Fernandez Pardo 2022-04-23 02:05:56 +02:00
parent 20cef3b4dd
commit 368e6eb0fa
1 changed files with 2 additions and 2 deletions

View File

@ -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" });