Skip to content

Commit

Permalink
Fix duplicate users in database
Browse files Browse the repository at this point in the history
  • Loading branch information
xuvi7 committed Sep 22, 2023
1 parent 543ed93 commit 3a44159
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,18 @@ app.post('/api/login', async (req, res) => {
app.post('/api/create', async (req, res) => {
console.log(req.body)
try {
const journal = await Journal.create({
email: req.body.email,
content: req.body.content,
const exist = await Journal.findOne({
email: req.body.email
})
res.json({ status: 'ok' })
if (!exist) {
const journal = await Journal.create({
email: req.body.email,
content: req.body.content,
})
res.json({ status: 'ok' })
} else {
res.json({ status: 'error', error: 'email already exists' })
}
} catch (err) {
console.log(err)
res.json({ status: 'error', error: 'error' })
Expand Down

0 comments on commit 3a44159

Please sign in to comment.