2016-06-09 22:28:21 +02:00
|
|
|
import * as ActionTypes from '../constants/constants'
|
|
|
|
import { browserHistory } from 'react-router'
|
|
|
|
import axios from 'axios'
|
|
|
|
|
|
|
|
|
|
|
|
const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000' : '/';
|
|
|
|
|
|
|
|
export function signUpUser(formValues) {
|
|
|
|
return function(dispatch) {
|
|
|
|
axios.post(`${ROOT_URL}/signup`, formValues)
|
|
|
|
.then(response => {
|
2016-06-10 00:41:40 +02:00
|
|
|
dispatch({ type: ActionTypes.AUTH_USER });
|
2016-06-09 22:28:21 +02:00
|
|
|
localStorage.setItem('token', response.data.token);
|
|
|
|
browserHistory.push('/');
|
|
|
|
})
|
|
|
|
.catch(response => dispatch(authError(response.data.error)));
|
|
|
|
}
|
2016-06-10 00:41:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function authError(error) {
|
|
|
|
return {
|
|
|
|
type: ActionTypes.AUTH_ERROR,
|
|
|
|
payload: error
|
|
|
|
};
|
2016-06-09 22:28:21 +02:00
|
|
|
}
|