blob: 30edda16c523b8f1a74e2aec1812d55c1012b18b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
import withSession from 'lib/withSession'
import dbConnect from 'lib/dbConnect'
import User from 'models/User'
export default withSession(async (req, res) => {
const {method} = req
await dbConnect()
switch (method) {
case 'POST':
try {
const {_id, email, isVerified, noteList} = await User.findByCredentials(req.body.email, req.body.password);
if (!email) { throw new Error('Something went wrong') }
const user = {_id, email, isVerified, isLoggedIn: true, noteList}
req.session.set('user', user)
await req.session.save()
res.status(201).json(user)
} catch (error) {
res.status(400).json({isLoggedIn: false})
}
break
default:
res.status(400).send({isLoggedIn: false})
break
}
})
|