mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-28 03:43:28 +10:00
Merge pull request #459 from sharetribe/fix-weird-auth-state
Try to keep auth info up to date when fetching current user
This commit is contained in:
commit
af708a4fae
2 changed files with 21 additions and 3 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { clearCurrentUser, currentUserShowRequest } from './user.duck';
|
||||
import { clearCurrentUser, currentUserShowRequest, currentUserShowSuccess } from './user.duck';
|
||||
import reducer, {
|
||||
authenticationInProgress,
|
||||
authInfoSuccess,
|
||||
|
|
@ -192,10 +192,10 @@ describe('Auth duck', () => {
|
|||
|
||||
describe('login thunk', () => {
|
||||
it('should dispatch success and fetch current user', () => {
|
||||
const initialState = reducer();
|
||||
const getState = () => ({ Auth: initialState });
|
||||
const sdk = { login: jest.fn(() => Promise.resolve({})) };
|
||||
const dispatch = createFakeDispatch(getState, sdk);
|
||||
const initialState = reducer();
|
||||
const username = 'x.x@example.com';
|
||||
const password = 'pass';
|
||||
|
||||
|
|
@ -205,6 +205,11 @@ describe('Auth duck', () => {
|
|||
loginRequest(),
|
||||
loginSuccess(),
|
||||
currentUserShowRequest(),
|
||||
|
||||
// Test restriction: Since the getState mock always returns
|
||||
// the initial state, user isn't marked as logged in and
|
||||
// current user is still null.
|
||||
currentUserShowSuccess(null),
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
|
@ -355,6 +360,11 @@ describe('Auth duck', () => {
|
|||
loginRequest(),
|
||||
loginSuccess(),
|
||||
currentUserShowRequest(),
|
||||
|
||||
// Test restriction: Since the getState mock always returns
|
||||
// the initial state, user isn't marked as logged in and
|
||||
// current user is still null.
|
||||
currentUserShowSuccess(null),
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { authInfo } from './Auth.duck';
|
||||
import { updatedEntities, denormalisedEntities } from '../util/data';
|
||||
import { TX_TRANSITION_PREAUTHORIZE } from '../util/propTypes';
|
||||
|
||||
|
|
@ -323,7 +324,8 @@ export const fetchCurrentUser = () =>
|
|||
const { isAuthenticated } = getState().Auth;
|
||||
|
||||
if (!isAuthenticated) {
|
||||
// Ignore when not logged in, current user should be null
|
||||
// Make sure current user is null
|
||||
dispatch(currentUserShowSuccess(null));
|
||||
return Promise.resolve({});
|
||||
}
|
||||
|
||||
|
|
@ -344,8 +346,14 @@ export const fetchCurrentUser = () =>
|
|||
if (!currentUser.attributes.emailVerified) {
|
||||
dispatch(fetchCurrentUserHasOrders());
|
||||
}
|
||||
|
||||
// Make sure auth info is up to date
|
||||
dispatch(authInfo());
|
||||
})
|
||||
.catch(e => {
|
||||
// Make sure auth info is up to date
|
||||
dispatch(authInfo());
|
||||
|
||||
// TODO: dispatch flash message: "Something went wrong while retrieving user info"
|
||||
dispatch(currentUserShowError(e));
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue