randydev commited on
Commit
b193ed1
·
verified ·
1 Parent(s): 92d9266

Update middleware/midware.js

Browse files
Files changed (1) hide show
  1. middleware/midware.js +2 -5
middleware/midware.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Database } from '../database/database.js';
2
  import { rateLimit } from 'express-rate-limit';
3
  import * as uuid from 'uuid';
4
 
@@ -6,15 +6,12 @@ const myUUID = uuid.v4();
6
 
7
  const authenticateApiKey = async (req, res, next) => {
8
  const apiKey = req.headers['x-api-key'];
9
- const dbClient = new Database("AkenoXJs", "FastJsAPI");
10
- const collection = dbClient.collection()
11
-
12
  if (!apiKey) {
13
  return res.status(401).json({ error: 'API Key required' });
14
  }
15
 
16
  try {
17
- const keyDoc = await collection('apiKeys').findOne({ key: apiKey });
18
  if (!keyDoc) {
19
  return res.status(403).json({ error: 'Invalid API Key' });
20
  }
 
1
+ import { Database, db } from '../database/database.js';
2
  import { rateLimit } from 'express-rate-limit';
3
  import * as uuid from 'uuid';
4
 
 
6
 
7
  const authenticateApiKey = async (req, res, next) => {
8
  const apiKey = req.headers['x-api-key'];
 
 
 
9
  if (!apiKey) {
10
  return res.status(401).json({ error: 'API Key required' });
11
  }
12
 
13
  try {
14
+ const keyDoc = await db('apiKeys').findOne({ key: apiKey });
15
  if (!keyDoc) {
16
  return res.status(403).json({ error: 'Invalid API Key' });
17
  }