Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop using logout when no locally stored user was found. #805

Merged
merged 1 commit into from
Nov 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/actions/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { notifSend } = notifActions;
export const AUTH_REQUEST = 'AUTH_REQUEST';
export const AUTH_SUCCESS = 'AUTH_SUCCESS';
export const AUTH_FAILURE = 'AUTH_FAILURE';
export const AUTH_REQUEST_DONE = 'AUTH_REQUEST_DONE';
export const LOGOUT = 'LOGOUT';

export function authenticating() {
Expand All @@ -29,6 +30,12 @@ export function authError(error) {
};
}

export function doneAuthenticating() {
return {
type: AUTH_REQUEST_DONE,
};
}

export function logout() {
return {
type: LOGOUT,
Expand All @@ -46,7 +53,7 @@ export function authenticateUser() {
if (user) {
dispatch(authenticate(user));
} else {
dispatch(logoutUser());
dispatch(doneAuthenticating());
}
})
.catch((error) => {
Expand Down
4 changes: 3 additions & 1 deletion src/reducers/auth.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Immutable from 'immutable';
import { AUTH_REQUEST, AUTH_SUCCESS, AUTH_FAILURE, LOGOUT } from '../actions/auth';
import { AUTH_REQUEST, AUTH_SUCCESS, AUTH_FAILURE, AUTH_REQUEST_DONE, LOGOUT } from '../actions/auth';

const auth = (state = null, action) => {
switch (action.type) {
Expand All @@ -9,6 +9,8 @@ const auth = (state = null, action) => {
return Immutable.fromJS({ user: action.payload });
case AUTH_FAILURE:
return Immutable.Map({ error: action.payload.toString() });
case AUTH_REQUEST_DONE:
return state.remove('isFetching');
case LOGOUT:
return state.remove('user').remove('isFetching');
default:
Expand Down