Skip to content

Commit a928f3d

Browse files
Merge pull request #193 from ekonstantinidis/fix-login
Fix Release Bug
2 parents adde38b + c83bb95 commit a928f3d

File tree

11 files changed

+17
-139
lines changed

11 files changed

+17
-139
lines changed

gulpfile.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ gulp.task('copy:fonts', function () {
6767
.pipe(gulp.dest('./dist/fonts'));
6868
});
6969

70-
gulp.task('build', ['copy:fonts', 'build:js', 'build:scss']);
70+
gulp.task('apply-prod-environment', function() {
71+
process.env.NODE_ENV = 'production';
72+
});
73+
7174
gulp.task('watch', ['watch:js', 'watch:scss']);
75+
gulp.task('build', ['copy:fonts', 'build:js', 'build:scss']);
76+
gulp.task('release', ['apply-prod-environment', 'build']);
7277
gulp.task('default', ['build']);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"watch": "gulp watch",
99
"package": "electron-packager . Gitify --overwrite --platform=darwin --arch=x64 --version=1.0.2 --asar=true --icon=images/app-icon.icns --prune --ignore='src' --ignore='coverage'",
1010
"codesign": "bash scripts/codesign.bash",
11-
"dist": "npm run build && npm run package && npm run codesign",
11+
"dist": "gulp release && npm run package && npm run codesign",
1212
"lint-js": "eslint 'src/js/' 'src/js/app.js' 'main.js'",
1313
"lint-sass": "sass-lint -c .sass-lint.yml -v -q",
1414
"mocha": "mocha --opts src/js/__tests__/__helpers__/mocha.opts",

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__/middleware/authentication.js

Lines changed: 0 additions & 56 deletions
This file was deleted.

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/middleware/authentication.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

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: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,19 @@ import * as storage from 'redux-storage';
55
import createEngine from 'redux-storage-engine-localstorage';
66
import filter from 'redux-storage-decorator-filter';
77

8-
import { checkAuth, fetchNotifications, UPDATE_SETTING } from '../actions';
9-
import authentication from '../middleware/authentication';
8+
import { fetchNotifications, UPDATE_SETTING, LOGIN_SUCCESS, LOGOUT } from '../actions';
109
import constants from '../utils/constants';
1110
import notifications from '../middleware/notifications';
1211
import requests from '../middleware/requests';
1312
import rootReducer from '../reducers';
1413

1514
export default function configureStore(initialState) {
16-
const engine = filter(createEngine(constants.STORAGE_KEY), ['settings']);
17-
const storageMiddleware = storage.createMiddleware(engine, [], [UPDATE_SETTING]);
15+
const engine = filter(createEngine(constants.STORAGE_KEY), ['settings', ['auth', 'token']]);
16+
const storageMiddleware = storage.createMiddleware(engine, [], [UPDATE_SETTING, LOGIN_SUCCESS, LOGOUT]);
1817

1918
const createStoreWithMiddleware = applyMiddleware(
2019
requests, // Should be passed before 'apiMiddleware'
2120
apiMiddleware,
22-
authentication,
2321
notifications,
2422
storageMiddleware
2523
)(createStore);
@@ -31,9 +29,7 @@ export default function configureStore(initialState) {
3129
load(store)
3230
.then(function (newState) {
3331
// Check if the user is logged in
34-
store.dispatch(checkAuth());
3532
const isLoggedIn = store.getState().auth.token !== null;
36-
3733
if (isLoggedIn) { store.dispatch(fetchNotifications()); }
3834
});
3935

0 commit comments

Comments
 (0)