aboutsummaryrefslogtreecommitdiffstats
path: root/pages/api/user.js
blob: 0b308f7913940eff805ff4e7fa5cc4b9138c08a6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import dbConnect from 'lib/dbConnect'
import withSession from 'lib/withSession'
import User from 'models/User'

export default withSession(async (req, res) => {
  await dbConnect()

  const user = req.session.get('user')
  const state = await User.state(user._id)

  if (user) {
    res.json({
      isLoggedIn: true,
      ...user,
      ...state
    })
  } else {
    res.json({
      isLoggedIn: false,
    })
  }
})