diff options
Diffstat (limited to 'public/bundle.js')
| -rw-r--r-- | public/bundle.js | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/public/bundle.js b/public/bundle.js index d6adf97..92ee2bf 100644 --- a/public/bundle.js +++ b/public/bundle.js @@ -220,7 +220,7 @@ function crud_fetch(type, tag) { }, show: function show(id) { - return (0, _nodeFetch2.default)(uri + id).then(function (req) { + return (0, _nodeFetch2.default)(uri + id, _get_headers(), _get_headers()).then(function (req) { return req.json(); }).catch(error); }, @@ -257,6 +257,7 @@ function _get_url(_url, data) { function _get_headers() { return { method: 'GET', + credentials: 'same-origin', headers: { 'Accept': 'application/json' } @@ -266,6 +267,7 @@ function post(data) { return { method: 'POST', body: JSON.stringify(data), + credentials: 'same-origin', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' @@ -276,6 +278,7 @@ function postBody(data) { return { method: 'POST', body: data, + credentials: 'same-origin', headers: { 'Accept': 'application/json' } @@ -285,6 +288,7 @@ function put(data) { return { method: 'PUT', body: JSON.stringify(data), + credentials: 'same-origin', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' @@ -295,6 +299,7 @@ function _destroy(data) { return { method: 'DELETE', body: JSON.stringify(data), + credentials: 'same-origin', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' @@ -1999,9 +2004,8 @@ function login(username, password) { return req.json(); }).then(function (data) { console.log(data); - dispatch(setCurrentUser(data)); + dispatch(setCurrentUser(data.user)); // dispatch(setToken(data.token)) - dispatch(checkin()); }).catch(function (error) { console.log(error); dispatch(setError(true)); @@ -2030,12 +2034,10 @@ function checkin() { fetch(api.checkin, (0, _crud.put)({})).then(function (req) { return req.json(); }).then(function (data) { - console.log(data); - dispatch(setCurrentUser(data)); - console.log('set current user'); + dispatch(setCurrentUser(data.user)); }).catch(function (error) { console.log(error); - dispatch(initialized(true)); + dispatch(initialized()); }); }; } @@ -2161,13 +2163,17 @@ var AuthGate = function (_Component2) { 'Loading' ); } - if (this.props.auth.isAuthenticated) return children; + if (this.props.auth.isAuthenticated) return (0, _preact.h)( + 'div', + null, + this.props.children + ); return (0, _preact.h)(AuthRouter, this.props); } }, { key: 'componentDidMount', value: function componentDidMount() { - this.props.actions.checkin(history); + this.props.actions.checkin(); } }]); @@ -2250,6 +2256,9 @@ var auth = function auth() { case _types2.default.auth.set_current_user: return _extends({}, state, { + loading: false, + initialized: true, + isAuthenticated: true, user: action.data, error: null }); @@ -2418,7 +2427,12 @@ var Login = function (_Component) { key: 'render', value: function render() { if (this.props.auth.isAuthenticated) { - return (0, _preact.h)(_reactRouterDom.Redirect, { to: this.props.auth.returnTo || '/' }); + var returnTo = this.props.auth.returnTo; + + if (!returnTo || returnTo.match(/(login|logout|signup)/i)) { + returnTo = '/'; + } + return (0, _preact.h)(_reactRouterDom.Redirect, { to: returnTo }); } return (0, _preact.h)( 'form', |
