fixed logout on drop down bar to stay on same page
This commit is contained in:
parent
74b6bca16c
commit
b60fbab744
3 changed files with 23 additions and 16 deletions
|
@ -19,25 +19,32 @@ class NavBar extends React.Component {
|
|||
this.checkForLoggedInUser();
|
||||
}
|
||||
checkForLoggedInUser () {
|
||||
const params = {
|
||||
credentials: 'include',
|
||||
}
|
||||
const params = {credentials: 'include'};
|
||||
request('/user', params)
|
||||
.then(({success, message}) => {
|
||||
.then(({success, message, data}) => {
|
||||
if (success) {
|
||||
this.props.onChannelLogin(message.channelName, message.shortChannelId, message.channelClaimId);
|
||||
this.props.onChannelLogin(data.channelName, data.shortChannelId, data.channelClaimId);
|
||||
} else {
|
||||
console.log('user was not logged in');
|
||||
console.log(message);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.log('authenticate user errored:', error);
|
||||
console.log('request encountered an error', error);
|
||||
});
|
||||
}
|
||||
logoutUser () {
|
||||
// send logout request to server
|
||||
window.location.href = '/logout'; // NOTE: replace with a call to the server that does not redirect
|
||||
// this.props.onChannelLogout()
|
||||
const params = {credentials: 'include'};
|
||||
request('/logout', params)
|
||||
.then(({success, message}) => {
|
||||
if (success) {
|
||||
this.props.onChannelLogout();
|
||||
} else {
|
||||
console.log(message);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.log('request encountered an error', error);
|
||||
});
|
||||
}
|
||||
handleSelection (event) {
|
||||
console.log('handling selection', event);
|
||||
|
|
|
@ -39,10 +39,15 @@ module.exports = (app) => {
|
|||
});
|
||||
})(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
|
||||
app.get('/user', (req, res) => {
|
||||
if (req.user) {
|
||||
res.status(200).json({success: true, message: req.user});
|
||||
res.status(200).json({success: true, data: req.user});
|
||||
} else {
|
||||
res.status(200).json({success: false, message: 'user is not logged in'});
|
||||
}
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
const { site } = require('../config/speechConfig.js');
|
||||
|
||||
module.exports = (app) => {
|
||||
// route to log out
|
||||
app.get('/logout', (req, res) => {
|
||||
req.logout();
|
||||
res.redirect('/');
|
||||
});
|
||||
// route to display login page
|
||||
app.get('/login', (req, res) => {
|
||||
res.status(200).render('index');
|
||||
|
|
Loading…
Reference in a new issue