Update index.js
Browse files
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(),
|