var express = require('express'); var router = express.Router(); const passport = require('passport'); const accounts = require('./../database/accounts/accounts'); const app = require('../app'); function adminLoggedIn(req, res, next) { if (req.user && req.user[2]) { next(); } else { req.flash('error', 'An admin account is required to access this page.'); res.redirect('/auth/login'); } } router.get('/login', (req, res, next) => { res.render('accounts/login', { title : "Login", message: req.flash('error') }); }); router.get('/logout', (req, res, next) => { req.logout(); res.redirect("/"); }); router.post('/login', passport.authenticate('local', { failureRedirect: '/auth/login', successRedirect: '/', failureFlash: "Invalid email or password.", }), (req, res, next) => { console.log(req.user); }); module.exports = router;