Skip to content

Commit

Permalink
Merge pull request #275 from Ansh101112/admin
Browse files Browse the repository at this point in the history
admin apis line added
  • Loading branch information
usha-madithati authored Jun 13, 2024
2 parents 33c9646 + 6bbbb9f commit ac468d8
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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) {
Expand Down

0 comments on commit ac468d8

Please sign in to comment.