Skip to content
Permalink
Browse files
fix: timings not being saved to db
  • Loading branch information
MantasMikal committed Feb 10, 2021
1 parent f46dd40 commit a363c82071bf5e8dd743039392dd546e9ec6cc30
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
@@ -18,34 +18,39 @@ router.post("/registration", async (req, res) => {

router.post("/fido2-authentication", async (req, res) => {
const { email, fido2AuthTimings } = req.body;

try {
const now = Date.now()
const dateCreated = new Date(now).toISOString()
// TODO: optimise
const user = await User.findOne({ email: email });
const timings = [
...user.fido2AuthTimings,
{
...fido2AuthTimings,
date: Date.now().toLocaleDateString("en-US"),
date: dateCreated,
},
];

await User.findOneAndUpdate({ email: email }, { fido2AuthTimings: timings });
console.log('Captured timings for user ' + email, timings)
return res.status(200).json({ status: "Success" });
} catch (err) {
console.log(err)
return res.status(500).json({ error: "Server error: " + err });
}
});

router.post("/pw-authentication", async (req, res) => {
const { email, passwordAuthTimings } = req.body;
try {
const now = Date.now()
const dateCreated = new Date(now).toISOString()

const user = await User.findOne({ email: email });
const timings = [
...user.passwordAuthTimings,
{
...passwordAuthTimings,
date: Date.now().toLocaleDateString("en-US"),
date: dateCreated,
},
];
await User.findOneAndUpdate({ email: email }, { passwordAuthTimings: timings });
@@ -57,7 +57,7 @@ app.use(
resave: false,
store: new MongoStore({ mongooseConnection: dbConnection.connection }),
saveUninitialized: false,
cookie: { secure: true },
cookie: { secure: config.mode === 'production' },
})
);

0 comments on commit a363c82

Please sign in to comment.