I am using hello.js to sign in.
hello('abc').login()
returns a promise.
It did sign in successfully, because hello.js itself saved the token in the local storage.
However, the code below sometimes does not dispatch the action SIGN_IN_SUCCEED
.
export const signInEpic = (action$, store) =>
action$
.ofType(SIGN_IN)
.mergeMap(action =>
Observable
.fromPromise(hello('msft').login({ scope }))
.map(response => ({
type: SIGN_IN_SUCCEED,
payload: response.authResponse.access_token
})
)
.catch(error => Observable.of({ type: SIGN_IN_FAILED, payload: error }))
);
UPDATE:
Jay's Pause on Caught Exceptions way helped me find the error. The code above has no issue. What causes the problem is that first I try to save the token to the store after getting SIGN_IN_SUCCEED
. Then I use the token immediately once the app sign in to fetch something. So when the fetch using token step runs before saving token in the store step, it causes the issue which also won't dispatch SIGN_IN_SUCCEED
.