Files
talk/routes/api/auth/index.js
T
Wyatt Johnson 745c579b82 Adjust redis to not start during webpack build
- Added new WEBPACK env var which is enabled during yarn build scripts
- Defered redis starting until listen is called
- Moved pubsub to a factory pattern init
- Async/Await'ed the routes
- Moved pubsub handle for routes into middleware
- Adjusted redis cache and job processors to have lazy connection
starting
- Disabled mongo from auto-connecting on require
- Adjusted package redis clients to act as factory singletons instead
2017-07-17 13:34:04 -06:00

39 lines
962 B
JavaScript

const express = require('express');
const {passport, HandleGenerateCredentials, HandleLogout} = require('../../../services/passport');
const router = express.Router();
/**
* This returns the user if they are logged in.
*/
router.get('/', (req, res, next) => {
if (!req.user) {
res.status(204).end();
return;
}
// Send back the user object.
res.json({user: req.user});
});
/**
* This blacklists the token used to authenticate.
*/
router.delete('/', HandleLogout);
// =============================================================================
// PASSPORT ROUTES
//==============================================================================
/**
* Local auth endpoint, will recieve a email and password
*/
router.post('/local', (req, res, next) => {
// Perform the local authentication.
passport.authenticate('local', {session: false}, HandleGenerateCredentials(req, res, next))(req, res, next);
});
module.exports = router;