2017-09-20 23:39:20 +02:00
|
|
|
const logger = require('winston');
|
|
|
|
const passport = require('passport');
|
|
|
|
|
|
|
|
module.exports = (app) => {
|
|
|
|
// route for sign up
|
|
|
|
app.post('/signup', passport.authenticate('local-signup'), (req, res) => {
|
2017-10-17 21:05:22 +02:00
|
|
|
logger.verbose(`successful signup for ${req.user.channelName}`);
|
2017-10-11 02:46:26 +02:00
|
|
|
res.status(200).json({
|
|
|
|
success : true,
|
|
|
|
channelName : req.user.channelName,
|
|
|
|
channelClaimId: req.user.channelClaimId,
|
|
|
|
shortChannelId: req.user.shortChannelId,
|
|
|
|
});
|
2017-09-20 23:39:20 +02:00
|
|
|
});
|
|
|
|
// route for log in
|
|
|
|
app.post('/login', passport.authenticate('local-login'), (req, res) => {
|
2017-11-30 23:46:32 +01:00
|
|
|
// logger.debug('req.user:', req.user); // req.user contains the authenticated user's info
|
2017-09-20 23:39:20 +02:00
|
|
|
logger.debug('successful login');
|
2017-10-07 01:42:19 +02:00
|
|
|
res.status(200).json({
|
|
|
|
success : true,
|
|
|
|
channelName : req.user.channelName,
|
|
|
|
channelClaimId: req.user.channelClaimId,
|
|
|
|
shortChannelId: req.user.shortChannelId,
|
|
|
|
});
|
2017-09-20 23:39:20 +02:00
|
|
|
});
|
2018-01-24 04:36:09 +01:00
|
|
|
// see if user is authenticated, and return credentials if so
|
|
|
|
app.get('/user', (req, res) => {
|
|
|
|
if (req.user) {
|
|
|
|
res.status(200).json({success: true, message: req.user});
|
|
|
|
} else {
|
|
|
|
res.status(200).json({success: false, message: 'user is not logged in'});
|
|
|
|
}
|
|
|
|
});
|
2017-09-20 23:39:20 +02:00
|
|
|
};
|