randydev commited on
Commit
0f816c4
·
verified ·
1 Parent(s): 0cb9b79

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +5 -0
index.js CHANGED
@@ -140,6 +140,11 @@ app.post('/v1/generate-key', async (req, res) => {
140
  if (isNaN(userIdNumber)) {
141
  return res.status(400).json({ error: "Invalid or missing user_id" });
142
  }
 
 
 
 
 
143
  const userDocument = {
144
  key: newKey,
145
  createdAt: new Date(),
 
140
  if (isNaN(userIdNumber)) {
141
  return res.status(400).json({ error: "Invalid or missing user_id" });
142
  }
143
+ const existingUser = await collection.findOne({ owner: userIdNumber });
144
+
145
+ if (existingUser) {
146
+ return res.status(200).json({ apiKey: `API key already: ${existingUser.key}` });
147
+ }
148
  const userDocument = {
149
  key: newKey,
150
  createdAt: new Date(),