Skip to content

Commit d6271ae

Browse files
author
Emmanouil Konstantinidis
committed
Remove Check auth action
1 parent 200566e commit d6271ae

File tree

6 files changed

+14
-66
lines changed

6 files changed

+14
-66
lines changed

src/js/__tests__/actions/index.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,6 @@ describe('actions/index.js', () => {
7373

7474
});
7575

76-
it('should check auth status', () => {
77-
78-
const token = 'HELLO';
79-
localStorage.setItem('token', token);
80-
81-
const expectedAction = {
82-
type: actions.CHECK_AUTH,
83-
token
84-
};
85-
86-
expect(actions.checkAuth()).to.eql(expectedAction);
87-
88-
});
89-
9076
it('should fetch notifications with success', () => {
9177
const notifications = [
9278
{

src/js/__tests__/reducers/auth.js

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from 'chai';
22
import reducer from '../../reducers/auth';
33
import {
4-
LOGIN_REQUEST, LOGIN_SUCCESS, LOGIN_FAILURE, LOGOUT, CHECK_AUTH
4+
LOGIN_REQUEST, LOGIN_SUCCESS, LOGIN_FAILURE, LOGOUT
55
} from '../../actions';
66

77
describe('reducers/auth.js', () => {
@@ -114,30 +114,4 @@ describe('reducers/auth.js', () => {
114114

115115
});
116116

117-
it('should handle CHECK_AUTH', () => {
118-
119-
const fakeState = {
120-
isFetching: false,
121-
failed: false,
122-
response: {},
123-
token: null
124-
};
125-
126-
const fakeToken = '123HELLOWORLDTOKEN';
127-
128-
expect(reducer(fakeState, {}).token).to.be.null;
129-
130-
const action = {
131-
type: CHECK_AUTH,
132-
token: fakeToken
133-
};
134-
135-
expect(reducer(fakeState, action)).to.eql({
136-
...initialState,
137-
token: fakeToken
138-
});
139-
140-
expect(reducer(fakeState, action).token).to.not.be.null;
141-
142-
});
143117
});

src/js/actions/index.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,6 @@ export function logout() {
4040
return { type: LOGOUT };
4141
};
4242

43-
export const CHECK_AUTH = 'CHECK_AUTH';
44-
export function checkAuth() {
45-
const userToken = localStorage.getItem('token');
46-
47-
return {
48-
type: CHECK_AUTH,
49-
token: userToken
50-
};
51-
};
52-
5343

5444
// Notifications
5545

src/js/components/navigation.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ export class Navigation extends React.Component {
1818
}
1919

2020
refreshNotifications() {
21-
this.props.fetchNotifications();
21+
const isLoggedIn = this.props.token !== null;
22+
if (isLoggedIn) {
23+
this.props.fetchNotifications();
24+
}
2225
}
2326

2427
goToSettings() {

src/js/reducers/auth.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
LOGIN_REQUEST, LOGIN_SUCCESS, LOGIN_FAILURE, LOGOUT, CHECK_AUTH
2+
LOGIN_REQUEST, LOGIN_SUCCESS, LOGIN_FAILURE, LOGOUT
33
} from '../actions';
44

55
const initialState = {
@@ -38,11 +38,6 @@ export default function reducer(state = initialState, action) {
3838
response: null,
3939
token: null
4040
};
41-
case CHECK_AUTH:
42-
return {
43-
...state,
44-
token: action.token
45-
};
4641
default:
4742
return state;
4843
}

src/js/store/configureStore.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
import { createStore, applyMiddleware } from 'redux';
22
import { apiMiddleware } from 'redux-api-middleware';
3+
import createLogger from 'redux-logger';
34

45
import * as storage from 'redux-storage';
56
import createEngine from 'redux-storage-engine-localstorage';
67
import filter from 'redux-storage-decorator-filter';
78

8-
import { checkAuth, fetchNotifications, UPDATE_SETTING } from '../actions';
9-
import authentication from '../middleware/authentication';
9+
import { fetchNotifications, UPDATE_SETTING, LOGIN_SUCCESS, LOGOUT } from '../actions';
1010
import constants from '../utils/constants';
1111
import notifications from '../middleware/notifications';
1212
import requests from '../middleware/requests';
1313
import rootReducer from '../reducers';
1414

1515
export default function configureStore(initialState) {
16-
const engine = filter(createEngine(constants.STORAGE_KEY), ['settings']);
17-
const storageMiddleware = storage.createMiddleware(engine, [], [UPDATE_SETTING]);
16+
const engine = filter(createEngine(constants.STORAGE_KEY), ['settings', ['auth', 'token']]);
17+
const storageMiddleware = storage.createMiddleware(engine, [], [UPDATE_SETTING, LOGIN_SUCCESS, LOGOUT]);
18+
19+
const logger = createLogger();
1820

1921
const createStoreWithMiddleware = applyMiddleware(
2022
requests, // Should be passed before 'apiMiddleware'
2123
apiMiddleware,
22-
authentication,
2324
notifications,
24-
storageMiddleware
25+
storageMiddleware,
26+
logger
2527
)(createStore);
2628

2729
const store = createStoreWithMiddleware(rootReducer, initialState);
@@ -31,9 +33,7 @@ export default function configureStore(initialState) {
3133
load(store)
3234
.then(function (newState) {
3335
// Check if the user is logged in
34-
store.dispatch(checkAuth());
3536
const isLoggedIn = store.getState().auth.token !== null;
36-
3737
if (isLoggedIn) { store.dispatch(fetchNotifications()); }
3838
});
3939

0 commit comments

Comments
 (0)