Skip to content

Commit e0d19ff

Browse files
committed
fixed
1 parent d3e9c76 commit e0d19ff

File tree

11 files changed

+106
-87
lines changed

11 files changed

+106
-87
lines changed

docs/assets/app.bundle.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/assets/app.vendor.bundle.js

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/Root.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,17 @@ const client = apolloClient;
3030

3131
class Root extends Component {
3232
render() {
33-
return <ApolloProvider store={store} client={client}>
33+
return (
34+
<ApolloProvider store={store} client={client}>
3435
<div>
3536
<Router history={syncedHistory}>
3637
<ScrollToTop>
3738
<App />
3839
</ScrollToTop>
3940
</Router>
4041
</div>
41-
</ApolloProvider>;
42+
</ApolloProvider>
43+
);
4244
}
4345
}
4446

src/app/components/privateRoute/PrivateRoute.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @flow weak
22

33
import React, {
4-
PureComponent
4+
Component
55
} from 'react';
66
import PropTypes from 'prop-types';
77
import {
@@ -11,7 +11,7 @@ import {
1111
} from "react-router-dom";
1212
import auth from '../../services/auth';
1313

14-
class PrivateRoute extends PureComponent {
14+
class PrivateRoute extends Component {
1515
static propTypes = {
1616
// react-router 4:
1717
match: PropTypes.object.isRequired,
@@ -23,17 +23,25 @@ class PrivateRoute extends PureComponent {
2323
};
2424

2525
render() {
26-
const { component, ...rest } = this.props;
26+
const {
27+
component: Component,
28+
...rest
29+
} = this.props;
2730
const { location } = this.props;
2831

2932
const isUserAuthenticated = this.isAuthenticated();
3033

3134
return (
32-
<Route {...rest}>
33-
{isUserAuthenticated
34-
? <component {...this.props} />
35-
: <Redirect to={{ pathname: "/login", state: { from: location } }} />}
36-
</Route>
35+
<Route
36+
{...rest}
37+
render={
38+
props => (
39+
isUserAuthenticated
40+
? <Component {...props} />
41+
: <Redirect to={{ pathname: "/login", state: { from: location } }} />
42+
)
43+
}
44+
/>
3745
);
3846
}
3947

src/app/containers/login/Login.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import gql from 'graphql-tag';
1010
import { graphql } from 'react-apollo';
1111

1212

13-
1413
/* -----------------------------------------
1514
GraphQL - Apollo client
1615
------------------------------------------*/

src/app/redux/modules/userAuth.js

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
11
// @flow weak
22

3-
import moment from 'moment';
4-
import { auth } from '../../services/auth';
3+
import moment from 'moment';
4+
import { auth } from '../../services/auth';
5+
56
const dateFormat = 'DD/MM/YYYY HH:mm';
67

78
/* -----------------------------------------
89
constants
910
------------------------------------------*/
1011
const CHECK_IS_USER_IS_AUTHENTICATED = 'CHECK_IS_USER_IS_AUTHENTICATED';
1112

12-
const RECEIVED_USER_LOGGED_IN = 'RECEIVED_USER_LOGGED_IN';
13-
const ERROR_USER_LOGGED_IN = 'ERROR_USER_LOGGED_IN';
13+
const RECEIVED_USER_LOGGED_IN = 'RECEIVED_USER_LOGGED_IN';
14+
const ERROR_USER_LOGGED_IN = 'ERROR_USER_LOGGED_IN';
1415

15-
const SET_LOADING_LOGGED_IN = 'SET_LOADING_LOGGED_IN';
16-
const UNSET_LOADING_LOGGED_IN = 'UNSET_LOADING_LOGGED_IN';
16+
const SET_LOADING_LOGGED_IN = 'SET_LOADING_LOGGED_IN';
17+
const UNSET_LOADING_LOGGED_IN = 'UNSET_LOADING_LOGGED_IN';
1718

18-
const RECEIVED_USER_REGISTER = 'RECEIVED_USER_REGISTER';
19-
const ERROR_USER_REGISTER = 'ERROR_USER_REGISTER';
19+
const RECEIVED_USER_REGISTER = 'RECEIVED_USER_REGISTER';
20+
const ERROR_USER_REGISTER = 'ERROR_USER_REGISTER';
2021

21-
const SET_LOADING_REGISTER = 'SET_LOADING_REGISTER';
22-
const UNSET_LOADING_REGISTER = 'UNSET_LOADING_REGISTER';
22+
const SET_LOADING_REGISTER = 'SET_LOADING_REGISTER';
23+
const UNSET_LOADING_REGISTER = 'UNSET_LOADING_REGISTER';
2324

24-
const SET_USER_LOGOUT = 'SET_USER_LOGOUT';
25+
const SET_USER_LOGOUT = 'SET_USER_LOGOUT';
2526

26-
const RESET_LOG_ERRORS = 'RESET_LOG_ERRORS';
27+
const RESET_LOG_ERRORS = 'RESET_LOG_ERRORS';
2728

2829
/* -----------------------------------------
2930
Reducer
3031
------------------------------------------*/
3132
const emptyUser = {
32-
id: null,
33+
id: '',
3334
username: '',
3435
lastLogin: '',
3536
createdAt: '',
@@ -51,30 +52,30 @@ export default function (state = initialState, action) {
5152
case RECEIVED_USER_REGISTER:
5253
return {
5354
...state,
54-
lastActionTime: action.time,
55+
lastActionTime: action.time,
5556
isAuthenticated: action.isAuthenticated,
56-
id: action.user.id,
57-
username: action.user.username,
58-
lastLogin: action.user.lastLogin,
59-
createdAt: action.user.createdAt,
60-
modifiedAt: action.user.modifiedAt,
57+
id: action.user.id,
58+
username: action.user.username,
59+
lastLogin: action.user.lastLogin,
60+
createdAt: action.user.createdAt,
61+
modifiedAt: action.user.modifiedAt,
6162
lastRefreshTime: action.time,
62-
error: null
63+
error: null
6364
};
6465

6566
case ERROR_USER_LOGGED_IN:
6667
case ERROR_USER_REGISTER:
6768
return {
6869
...state,
69-
lastActionTime: action.time,
70-
isAuthenticated: action.isAuthenticated,
70+
lastActionTime: action.time,
71+
isAuthenticated: action.isAuthenticated,
7172
// errors:
7273
error: {...action.error},
7374
// user infos:
74-
id: initialState.id,
75-
username: initialState.username,
76-
lastLogin: initialState.lastLogin,
77-
createdAt: initialState.createdAt,
75+
id: initialState.id,
76+
username: initialState.username,
77+
lastLogin: initialState.lastLogin,
78+
createdAt: initialState.createdAt,
7879
modifiedAt: initialState.modifiedAt
7980
};
8081

@@ -84,33 +85,33 @@ export default function (state = initialState, action) {
8485
case UNSET_LOADING_REGISTER:
8586
return {
8687
...state,
87-
lastActionTime: action.time,
88+
lastActionTime: action.time,
8889
mutationLoading: action.loading
8990
};
9091

9192
case CHECK_IS_USER_IS_AUTHENTICATED:
9293
return {
9394
...state,
94-
lastActionTime: action.time,
95-
isAuthenticated: action.isAuthenticated,
95+
lastActionTime: action.time,
96+
isAuthenticated: action.isAuthenticated,
9697
// user infos from storage if authenticated:
97-
id: action.user.id,
98-
username: action.user.username,
99-
lastLogin: action.user.lastLogin,
100-
createdAt: action.user.createdAt,
101-
modifiedAt: action.user.modifiedAt
98+
id: action.user.id,
99+
username: action.user.username,
100+
lastLogin: action.user.lastLogin,
101+
createdAt: action.user.createdAt,
102+
modifiedAt: action.user.modifiedAt
102103
};
103104

104105
case SET_USER_LOGOUT:
105106
return {
106107
...state,
107-
lastActionTime: action.time,
108+
lastActionTime: action.time,
108109
isAuthenticated: action.isAuthenticated,
109-
id: action.user.id,
110-
username: action.user.username,
111-
lastLogin: action.user.lastLogin,
112-
createdAt: action.user.createdAt,
113-
modifiedAt: action.user.modifiedAt
110+
id: action.user.id,
111+
username: action.user.username,
112+
lastLogin: action.user.lastLogin,
113+
createdAt: action.user.createdAt,
114+
modifiedAt: action.user.modifiedAt
114115
};
115116

116117
case RESET_LOG_ERRORS:

src/app/redux/modules/views.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ const dateFormat = 'DD/MM/YYYY HH:mm';
77
constants
88
------------------------------------------*/
99
// non protected views:
10-
const ENTER_HOME_VIEW = 'ENTER_HOME_VIEW';
11-
const LEAVE_HOME_VIEW = 'LEAVE_HOME_VIEW';
12-
const ENTER_ABOUT_VIEW = 'ENTER_ABOUT_VIEW';
13-
const LEAVE_ABOUT_VIEW = 'LEAVE_ABOUT_VIEW';
14-
const ENTER_LOGIN_VIEW = 'ENTER_LOGIN_VIEW';
15-
const LEAVE_LOGIN_VIEW = 'LEAVE_LOGIN_VIEW';
10+
const ENTER_HOME_VIEW = 'ENTER_HOME_VIEW';
11+
const LEAVE_HOME_VIEW = 'LEAVE_HOME_VIEW';
12+
const ENTER_ABOUT_VIEW = 'ENTER_ABOUT_VIEW';
13+
const LEAVE_ABOUT_VIEW = 'LEAVE_ABOUT_VIEW';
14+
const ENTER_LOGIN_VIEW = 'ENTER_LOGIN_VIEW';
15+
const LEAVE_LOGIN_VIEW = 'LEAVE_LOGIN_VIEW';
1616
const ENTER_REGISTER_VIEW = 'ENTER_REGISTER_VIEW';
1717
const LEAVE_REGISTER_VIEW = 'LEAVE_REGISTER_VIEW';
1818
// protected views:
@@ -43,8 +43,8 @@ export default function (state = initialState, action) {
4343
if (state.currentView !== action.currentView) {
4444
return {
4545
...state,
46-
currentView: action.currentView,
47-
enterTime: currentTime
46+
currentView: action.currentView,
47+
enterTime: currentTime
4848
};
4949
}
5050
return state;

src/app/services/apollo/index.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33

44
import {
55
ApolloClient,
6-
createNetworkInterface
6+
createNetworkInterface,
7+
addTypename
78
} from 'react-apollo';
89
import { appConfig } from '../../config';
910

1011
const networkInterface = createNetworkInterface({
11-
uri: appConfig.apollo.networkInterface,
12-
transportBatching: true
12+
uri: appConfig.apollo.networkInterface
13+
// connectToDevTools: true
14+
// transportBatching: true
1315
});
1416

1517
networkInterface.use([{
@@ -19,14 +21,15 @@ networkInterface.use([{
1921
}
2022
// get the authentication token from local storage if it exists
2123
const token = localStorage.getItem('token');
22-
req.options.headers.authorization = token ? `Bearer ${token}` : null;
24+
if (token) {
25+
req.options.headers.authorization = token ? `Bearer ${token}` : null;
26+
}
2327
next();
2428
}
2529
}]);
2630

2731
export const apolloClient = new ApolloClient({
28-
networkInterface,
29-
queryTransformer: addTypename
32+
networkInterface
3033
});
3134

3235
export default apolloClient;

src/app/views/login/Login.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,11 @@ class Login extends PureComponent {
154154
this.setState({ password: event.target.value });
155155
}
156156

157-
handlesOnLogin = (event) => {
157+
handlesOnLogin = async (event) => {
158158
event.preventDefault();
159159
const {
160160
loginUser,
161-
router
161+
history
162162
} = this.props;
163163

164164
const {
@@ -173,9 +173,12 @@ class Login extends PureComponent {
173173
}
174174
};
175175

176-
loginUser({variables})
177-
.then(() => router.push({ pathname: '/protected' }))
178-
.catch(() => console.log('login went wrong...'));
176+
try {
177+
await loginUser({variables});
178+
history.push({ pathname: '/protected' });
179+
} catch (error) {
180+
console.log('login went wrong..., error: ', error);
181+
}
179182
}
180183

181184
closeError = (event) => {

src/app/views/register/Register.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,11 @@ class Register extends PureComponent {
161161
this.setState({ password: event.target.value });
162162
}
163163

164-
handlesOnRegister = (event) => {
164+
handlesOnRegister = async (event) => {
165165
event.preventDefault();
166166
const {
167167
registerUser,
168-
router
168+
history
169169
} = this.props;
170170

171171
const {
@@ -194,9 +194,12 @@ class Register extends PureComponent {
194194
return;
195195
}
196196

197-
registerUser({variables})
198-
.then(() => router.push({ pathname: '/protected' }))
199-
.catch((err) => console.log('register user went wrong..., ', err));
197+
try {
198+
await registerUser({variables});
199+
history.push({ pathname: '/protected' });
200+
} catch (error) {
201+
console.log('register user went wrong..., error: ', error)
202+
}
200203
}
201204

202205
isValidEmail(email = '') {

0 commit comments

Comments
 (0)