Skip to content
Permalink
1231f36974
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
35 lines (32 sloc) 1.15 KB
import express from "express";
// import cfg from "config";
import User from "../models/user.js";
import AccountVerificationCode from "../models/accountVerificationCode.js";
const mode = process.env.NODE_ENV || "dev";
// const config = cfg.get(mode);
const router = express.Router();
router.post("/verify-account", async (req, res) => {
const { email, secretCode } = req.body;
try {
const verificationCode = await AccountVerificationCode.findOne({ code: secretCode });
const user = await User.findOne({ email: email });
if (user && verificationCode && verificationCode.email === user.email) {
await User.findOneAndUpdate(
{ email: email },
{
status: "active",
registrationTimings: {
...user.registrationTimings,
verificationDuration: (Date.now() - user.registrationTimings.regEndTime) / 1000,
},
}
);
return res.status(200).json({ status: "Success" });
} else {
return res.status(401).json({ error: "Incorrect verification code" });
}
} catch (err) {
return res.status(500).json({ error: "Server error: " + err });
}
});
export default router;