import withSession from 'hocs/withSession' import dbConnect from 'configs/dbConnect' import User from 'models/User' export default withSession(async (req, res) => { const { method } = req await dbConnect() switch (method) { case 'POST': try { const { email, password } = JSON.parse(req.body) const { _id, isVerified, noteList, theme, language } = await User.findByCredentials(email, password) if (!email) { throw new Error('Something went wrong') } const user = { _id, email, isVerified, isLoggedIn: true, noteList, theme, language } 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 } })