summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2018-09-17 03:24:53 +0200
committerJules Laplace <julescarbon@gmail.com>2018-09-17 03:24:53 +0200
commit6eceaa562b5752ec884c15466241228db3955dc8 (patch)
tree87791a1821144388f966ae16235a639c528b2b30 /app
parenta70df1505e8d4dfbb7540b6e3d5ffe5da2f9609c (diff)
ughhhhhhhg
Diffstat (limited to 'app')
-rw-r--r--app/client/auth/auth.actions.js2
-rw-r--r--app/client/auth/auth.gate.js25
-rw-r--r--app/client/auth/login.component.js2
-rw-r--r--app/server/util/auth.js9
4 files changed, 25 insertions, 13 deletions
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 (
<BrowserRouter>
<div>
<div className="diamond"></div>
<Switch>
- <Route exact path='/' component={Login} />
- <Route exact path='/login' component={Login} />
- <Route exact path='/logout' component={Logout} />
- <Route exact path='/signup' component={Signup} />
- <Route component={props => {
- this.props.actions.setReturnTo(props.location.pathname)
- return (
- <Redirect to="/login" />
- )
- }} />
+ <Route path='/logout' component={Logout} />
+ <Route path='/signup' component={Signup} />
+ <Route component={Login} />
</Switch>
</div>
</BrowserRouter>
@@ -41,11 +35,12 @@ class AuthRouter extends Component {
class AuthGate extends Component {
render(){
+ console.log(this.props.auth)
if (!this.props.auth.initialized) {
return <div className='loading'>Loading</div>
}
if (this.props.auth.isAuthenticated) return <div>{this.props.children}</div>
- return <AuthRouter {...this.props} />
+ return <AuthRouter />
}
componentDidMount(){
this.props.actions.checkin()
@@ -61,3 +56,11 @@ const mapDispatchToProps = (dispatch) => ({
});
export default connect(mapStateToProps, mapDispatchToProps)(AuthGate);
+
+ // <Route component={props => {
+ // console.log(window.location.pathname)
+ // this.props.actions.setReturnTo(window.location.pathname)
+ // return (
+ // <Redirect to="/login" />
+ // )
+ // }} /> \ 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')
}