forked from bradtraversy/storybooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
30 lines (26 loc) · 692 Bytes
/
index.js
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
30
const express = require('express')
const router = express.Router()
const { ensureAuth, ensureGuest } = require('../middleware/auth')
const Story = require('../models/Story')
// @desc Login/Landing page
// @route GET /
router.get('/', ensureGuest, (req, res) => {
res.render('login', {
layout: 'login',
})
})
// @desc Dashboard
// @route GET /dashboard
router.get('/dashboard', ensureAuth, async (req, res) => {
try {
const stories = await Story.find({ user: req.user.id }).lean()
res.render('dashboard', {
name: req.user.firstName,
stories,
})
} catch (err) {
console.error(err)
res.render('error/500')
}
})
module.exports = router