This repository has been archived on 2024-04-05. You can view files and clone it, but cannot push or open issues/pull-requests.
score-tracker/routes/auth.js

27 lines
663 B
JavaScript
Raw Normal View History

2021-11-25 01:25:27 +00:00
var express = require('express');
2021-11-25 00:56:04 +00:00
var router = express.Router();
2021-11-25 04:05:33 +00:00
const passport = require('passport');
2021-11-25 00:56:04 +00:00
const app = require('../app');
2021-11-25 03:58:49 +00:00
router.get('/login', (req, res, next) => {
2021-11-25 04:22:17 +00:00
res.render('accounts/login', { title : "Login", message: req.flash('error') });
2021-11-25 03:58:49 +00:00
});
2021-11-25 00:56:04 +00:00
2021-11-25 04:07:13 +00:00
router.get('/logout', (req, res, next) => {
req.logout();
res.redirect("/");
});
2021-11-25 03:58:49 +00:00
router.post('/login',
2021-11-25 04:05:33 +00:00
passport.authenticate('local', {
2021-11-25 04:22:17 +00:00
failureRedirect: '/auth/login',
successRedirect: '/',
failureFlash: "Invalid email or password.",
2021-11-25 03:58:49 +00:00
}),
(req, res, next) => {
console.log(req.user);
2021-11-25 00:56:04 +00:00
});
2021-11-25 01:25:27 +00:00
2021-11-25 00:56:04 +00:00
module.exports = router;