Skip to content

Commit

Permalink
Fix multiple redirect events on auth error
Browse files Browse the repository at this point in the history
  • Loading branch information
fxzhukov committed Mar 4, 2019
1 parent 5dca68b commit de78b59
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions packages/ra-core/src/sideEffect/auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { all, put, call, select, takeEvery } from 'redux-saga/effects';
import {
all,
put,
call,
select,
takeLatest,
takeEvery,
} from 'redux-saga/effects';
import { push, replace } from 'react-router-redux';

import { AuthProvider } from '../types';
Expand Down Expand Up @@ -46,18 +53,18 @@ export default (authProvider?: AuthProvider) => {
select(nextPathnameSelector);
yield put(push(redirectTo || '/'));
} catch (e) {
yield put({
type: USER_LOGIN_FAILURE,
error: e,
meta: { auth: true },
});
const errorMessage =
typeof e === 'string'
? e
: typeof e === 'undefined' || !e.message
? 'ra.auth.sign_in_error'
: e.message;
yield put(showNotification(errorMessage, 'warning'));
yield put({
type: USER_LOGIN_FAILURE,
error: e,
meta: { auth: true },
});
}
break;
}
Expand Down Expand Up @@ -111,7 +118,7 @@ export default (authProvider?: AuthProvider) => {
return function* watchAuthActions() {
yield all([
takeEvery(action => action.meta && action.meta.auth, handleAuth),
takeEvery(FETCH_ERROR, handleAuth),
takeLatest(FETCH_ERROR, handleAuth),
]);
};
};

0 comments on commit de78b59

Please sign in to comment.