diff options
| -rw-r--r-- | app/client/auth/auth.actions.js | 9 | ||||
| -rw-r--r-- | app/client/auth/signup.component.js | 6 | ||||
| -rw-r--r-- | app/client/index.jsx | 17 | ||||
| -rw-r--r-- | app/server/util/auth.js | 13 |
4 files changed, 28 insertions, 17 deletions
diff --git a/app/client/auth/auth.actions.js b/app/client/auth/auth.actions.js index 33af206..c4d9b52 100644 --- a/app/client/auth/auth.actions.js +++ b/app/client/auth/auth.actions.js @@ -46,10 +46,9 @@ export function login(username, password) { .then(data => { console.log(data) dispatch(setCurrentUser(data.user)) - // dispatch(setToken(data.token)) }) .catch(error => { - console.log(error) + console.error(error) dispatch(setError(true)) }) } @@ -62,10 +61,10 @@ export function signup(data) { .then(req => req.json()) .then(data => { console.log(data) - dispatch(login(data.username, data.password)) + dispatch(setCurrentUser(data.user)) }) .catch(error => { - console.log(error) + console.error(error) dispatch(initialized()) }) } @@ -80,7 +79,7 @@ export function checkin() { dispatch(setCurrentUser(data.user)) }) .catch(error => { - console.log(error) + console.error(error) dispatch(initialized()) }) } diff --git a/app/client/auth/signup.component.js b/app/client/auth/signup.component.js index 87e6ac6..4882681 100644 --- a/app/client/auth/signup.component.js +++ b/app/client/auth/signup.component.js @@ -39,7 +39,11 @@ class Signup extends Component { } render(){ if (this.props.auth.isAuthenticated) { - return <Redirect to={this.props.auth.returnTo || '/'} /> + let { returnTo } = this.props.auth + if (!returnTo || returnTo.match(/(api|login|logout|signup)/i)) { + returnTo = '/' + } + return <Redirect to={returnTo} /> } return ( <form onSubmit={this.handleSubmit}> diff --git a/app/client/index.jsx b/app/client/index.jsx index 614bb35..9c18251 100644 --- a/app/client/index.jsx +++ b/app/client/index.jsx @@ -1,6 +1,6 @@ import { h, render } from 'preact' import { Provider } from 'react-redux' -import { BrowserRouter, Route } from 'react-router-dom' +import { BrowserRouter, Switch, Route, Redirect } from 'react-router-dom' // import client from './client' import { store, history } from './store' @@ -24,16 +24,17 @@ const app = ( <Provider store={store}> <Auth.Gate> <BrowserRouter> - <div> + <Switch> <Route exact path='/' component={Dashboard} /> - <Route path='/system/' component={System} /> - <Route path='/dashboard/' component={Dashboard} /> - <Route path='/logout/' component={Auth.Logout} /> + <Route exact path='/system/' component={System} /> + <Route exact path='/dashboard/' component={Dashboard} /> + <Route exact path='/logout/' component={Auth.Logout} /> {module_list} - <Route path='/' component={Header} /> - <AudioPlayer /> - </div> + <Route exact path='/' component={Header} /> + <Route component={() => <Redirect to="/" />} /> + </Switch> </BrowserRouter> + <AudioPlayer /> </Auth.Gate> </Provider> ) diff --git a/app/server/util/auth.js b/app/server/util/auth.js index 0d7dbd8..1515bb4 100644 --- a/app/server/util/auth.js +++ b/app/server/util/auth.js @@ -19,7 +19,6 @@ export function route(app, serve_index){ app.put("/api/signup", checkIfUserExists, createUser, - passport.authenticate("local"), login) app.put("/api/login", passport.authenticate("local"), @@ -79,8 +78,16 @@ export function createUser(req, res, next) { profile: {}, } userModel.create(data) - .then(user => next(user)) - .catch(err => res.json({ error })) + .then(user => { + console.log('created userrrrr', user) + req.login(user, err => { + console.log(err) + err ? next(err) : next() + }) + }) + .catch(err => { + res.json({ error }) + }) } export function login(req, res) { |
