Skip to content
Permalink
fafeea9e83
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
57 lines (51 sloc) 1.71 KB
import express from "express";
// import cfg from "config";
import User from "../models/user.js";
// const mode = process.env.NODE_ENV || "dev";
// const config = cfg.get(mode);
const router = express.Router();
router.post("/registration", async (req, res) => {
const { email, registrationTimings } = req.body;
try {
await User.findOneAndUpdate({ email: email }, { registrationTimings: registrationTimings });
return res.status(200).json({ status: "Success" });
} catch (err) {
return res.status(500).json({ error: "Server error: " + err });
}
});
router.post("/fido2-authentication", async (req, res) => {
const { email, fido2AuthTimings } = req.body;
try {
// TODO: optimise
const user = await User.findOne({ email: email });
const timings = [
...user.fido2AuthTimings,
{
...fido2AuthTimings,
date: Date.now().toLocaleDateString("en-US"),
},
];
await User.findOneAndUpdate({ email: email }, { fido2AuthTimings: timings });
return res.status(200).json({ status: "Success" });
} catch (err) {
return res.status(500).json({ error: "Server error: " + err });
}
});
router.post("/pw-authentication", async (req, res) => {
const { email, passwordAuthTimings } = req.body;
try {
const user = await User.findOne({ email: email });
const timings = [
...user.passwordAuthTimings,
{
...passwordAuthTimings,
date: Date.now().toLocaleDateString("en-US"),
},
];
await User.findOneAndUpdate({ email: email }, { passwordAuthTimings: timings });
return res.status(200).json({ status: "Success" });
} catch (err) {
return res.status(500).json({ error: "Server error: " + err });
}
});
export default router;