React router #343

Merged
bones7242 merged 96 commits from react-router into master 2018-02-15 08:02:17 +01:00
3 changed files with 23 additions and 16 deletions
Showing only changes of commit b60fbab744 - Show all commits

View file

@ -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);

View file

@ -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'});
}

View file

@ -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');