fixed logout on drop down bar to stay on same page

This commit is contained in:
bill bittner 2018-02-02 15:14:57 -08:00
parent 74b6bca16c
commit b60fbab744
3 changed files with 23 additions and 16 deletions

View file

@ -19,25 +19,32 @@ class NavBar extends React.Component {
this.checkForLoggedInUser(); this.checkForLoggedInUser();
} }
checkForLoggedInUser () { checkForLoggedInUser () {
const params = { const params = {credentials: 'include'};
credentials: 'include',
}
request('/user', params) request('/user', params)
.then(({success, message}) => { .then(({success, message, data}) => {
if (success) { if (success) {
this.props.onChannelLogin(message.channelName, message.shortChannelId, message.channelClaimId); this.props.onChannelLogin(data.channelName, data.shortChannelId, data.channelClaimId);
} else { } else {
console.log('user was not logged in'); console.log(message);
} }
}) })
.catch(error => { .catch(error => {
console.log('authenticate user errored:', error); console.log('request encountered an error', error);
}); });
} }
logoutUser () { logoutUser () {
// send logout request to server const params = {credentials: 'include'};
window.location.href = '/logout'; // NOTE: replace with a call to the server that does not redirect request('/logout', params)
// this.props.onChannelLogout() .then(({success, message}) => {
if (success) {
this.props.onChannelLogout();
} else {
console.log(message);
}
})
.catch(error => {
console.log('request encountered an error', error);
});
} }
handleSelection (event) { handleSelection (event) {
console.log('handling selection', event); console.log('handling selection', event);

View file

@ -39,10 +39,15 @@ module.exports = (app) => {
}); });
})(req, res, next); })(req, res, next);
}); });
// route to log out
app.get('/logout', (req, res) => {
req.logout();
res.status(200).json({success: true, message: 'you successfully logged out'});
});
// see if user is authenticated, and return credentials if so // see if user is authenticated, and return credentials if so
app.get('/user', (req, res) => { app.get('/user', (req, res) => {
if (req.user) { if (req.user) {
res.status(200).json({success: true, message: req.user}); res.status(200).json({success: true, data: req.user});
} else { } else {
res.status(200).json({success: false, message: 'user is not logged in'}); res.status(200).json({success: false, message: 'user is not logged in'});
} }

View file

@ -1,11 +1,6 @@
const { site } = require('../config/speechConfig.js'); const { site } = require('../config/speechConfig.js');
module.exports = (app) => { module.exports = (app) => {
// route to log out
app.get('/logout', (req, res) => {
req.logout();
res.redirect('/');
});
// route to display login page // route to display login page
app.get('/login', (req, res) => { app.get('/login', (req, res) => {
res.status(200).render('index'); res.status(200).render('index');