From 6eceaa562b5752ec884c15466241228db3955dc8 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 17 Sep 2018 03:24:53 +0200 Subject: ughhhhhhhg --- app/client/auth/auth.actions.js | 2 +- app/client/auth/auth.gate.js | 25 ++++++++++++++----------- app/client/auth/login.component.js | 2 ++ app/server/util/auth.js | 9 ++++++++- 4 files changed, 25 insertions(+), 13 deletions(-) (limited to 'app') diff --git a/app/client/auth/auth.actions.js b/app/client/auth/auth.actions.js index 42df1e2..c075646 100644 --- a/app/client/auth/auth.actions.js +++ b/app/client/auth/auth.actions.js @@ -80,7 +80,7 @@ export function checkin() { dispatch(setCurrentUser(data.user)) }) .catch(error => { - console.error(error) + console.error('err', error) dispatch(initialized()) }) } diff --git a/app/client/auth/auth.gate.js b/app/client/auth/auth.gate.js index 087dfc6..07ab399 100644 --- a/app/client/auth/auth.gate.js +++ b/app/client/auth/auth.gate.js @@ -14,21 +14,15 @@ import { randint } from '../util/math' class AuthRouter extends Component { render(){ + console.log(this.props, Login) return (
- - - - - { - this.props.actions.setReturnTo(props.location.pathname) - return ( - - ) - }} /> + + +
@@ -41,11 +35,12 @@ class AuthRouter extends Component { class AuthGate extends Component { render(){ + console.log(this.props.auth) if (!this.props.auth.initialized) { return
Loading
} if (this.props.auth.isAuthenticated) return
{this.props.children}
- return + return } componentDidMount(){ this.props.actions.checkin() @@ -61,3 +56,11 @@ const mapDispatchToProps = (dispatch) => ({ }); export default connect(mapStateToProps, mapDispatchToProps)(AuthGate); + + // { + // console.log(window.location.pathname) + // this.props.actions.setReturnTo(window.location.pathname) + // return ( + // + // ) + // }} /> \ No newline at end of file diff --git a/app/client/auth/login.component.js b/app/client/auth/login.component.js index 2ef01a6..723d68a 100644 --- a/app/client/auth/login.component.js +++ b/app/client/auth/login.component.js @@ -15,6 +15,7 @@ class Login extends Component { } constructor() { super() + console.log('yooooooo') this.handleChange = this.handleChange.bind(this) this.handleSubmit = this.handleSubmit.bind(this) } @@ -30,6 +31,7 @@ class Login extends Component { this.props.actions.login(this.state.username, this.state.password) } render(){ + console.log('yooooooo') if (this.props.auth.isAuthenticated) { let { returnTo } = this.props.auth if (!returnTo || returnTo.match(/(login|logout|signup)/i)) { diff --git a/app/server/util/auth.js b/app/server/util/auth.js index 1515bb4..6a9bfe0 100644 --- a/app/server/util/auth.js +++ b/app/server/util/auth.js @@ -24,7 +24,7 @@ export function route(app, serve_index){ passport.authenticate("local"), login) app.put("/api/checkin", - ensureAuthenticated, + ensureAPIAuthenticated, checkin) } @@ -36,6 +36,13 @@ export function ensureAuthenticated(req, res, next) { next() } +export function ensureAPIAuthenticated(req, res, next) { + if (!req.isAuthenticated()) { + return res.send(500) + } + next() +} + export function getUserByUsername(username) { return userModel.show(sanitizeName(username), 'username') } -- cgit v1.2.3-70-g09d2