Skip to content

Commit

Permalink
added route to let user validate their user session
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueAccords committed May 9, 2018
1 parent 4ec6ed7 commit 54f8e5e
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 1 deletion.
199 changes: 199 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
},
"homepage": "https://github.com/BlueAccords/xtra-folder#readme",
"dependencies": {
"react-router-redux": "^5.0.0-alpha.9",
"redux-saga-thunk": "^0.7.1"
}
}
2 changes: 1 addition & 1 deletion server/authentication/local-strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ passport.use(new LocalStrategy({
if(authHelpers.comparePassword(password, user.password_digest)) {
return done(null, user, 'success');
} else {
return done(null, false, 'passwords do not match');
return done(null, false, 'Invalid password');
}
})
.catch((err) => { return done(err); });
Expand Down
9 changes: 9 additions & 0 deletions server/controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,14 @@ module.exports = {
} else {
ctrlHelpers.handleResponse(false, res, 400, 'no user is currently logged in');
}
},
// used to check if client has a session cookie and if it is validate.
validateSession: async function(req, res) {
if(req.user && req.isAuthenticated()) {
console.log(req.user);
ctrlHelpers.handleResponse(true, res, 200, 'success', req.user);
} else {
throw Boom.badRequest('User is not logged in');
}
}
}
1 change: 1 addition & 0 deletions server/routes/v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const authBaseUrl = '/auth';
router.post(`${authBaseUrl}/register`, authController.register);
router.post(`${authBaseUrl}/login`, authController.login);
router.get(`${authBaseUrl}/logout`, authController.logout);
router.get(`${authBaseUrl}/validate`, authController.validateSession);

// game
const gameBaseUrl = '/game';
Expand Down

0 comments on commit 54f8e5e

Please sign in to comment.