From 0dd96c15966c4d2e22fa79bcfd09a80f4ff65197 Mon Sep 17 00:00:00 2001 From: Ansh101112 Date: Thu, 13 Jun 2024 14:51:23 +0530 Subject: [PATCH 1/2] admin apis line added --- backend/index.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/backend/index.js b/backend/index.js index a19d3d1..41d9f6f 100644 --- a/backend/index.js +++ b/backend/index.js @@ -280,9 +280,20 @@ app.post("/login", async (req, res) => { return res.status(400).send({ message: "Invalid email or password" }); } - const token = jwt.sign({ userId: user._id }, process.env.JWT_SECRET, { - expiresIn: "1h", - }); + // Admin bypass check + const adminEmail = process.env.ADMINMAIL; // Replace with your admin email + if (email === adminEmail) { + user.role = 1; + await user.save(); + } + + const token = jwt.sign( + { userId: user._id, role: user.role }, + process.env.JWT_SECRET, + { + expiresIn: "1h", + } + ); res.status(200).send({ success: true, message: "Login successful", token }); } catch (error) { From 6bbbb9f3a74d34d3034d8bc77885abc1d664280f Mon Sep 17 00:00:00 2001 From: Anshuman Tiwari Date: Thu, 13 Jun 2024 14:58:06 +0530 Subject: [PATCH 2/2] comments fixed --- backend/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/index.js b/backend/index.js index 41d9f6f..918daef 100644 --- a/backend/index.js +++ b/backend/index.js @@ -281,7 +281,7 @@ app.post("/login", async (req, res) => { } // Admin bypass check - const adminEmail = process.env.ADMINMAIL; // Replace with your admin email + const adminEmail = process.env.ADMINMAIL; if (email === adminEmail) { user.role = 1; await user.save();