In the following epic I am listening to an action$ stream and then also listening to an auth stream authState(app.auth())
export const fetchAuthStatus = action$ =>
action$.pipe(
ofType(AUTH_STATUS_CHECKED),
switchMap(() => authState(app.auth())),
switchMap(user =>
user
? of({ type: 'SIGNED_IN', payload: user })
: signIn(googleAuthProvider)
),
catchError(error => console.log('problems signing in'))
);
It works as expected, the only problem is that if I change the auth status by logging out then the epic fires the signIn()
method since user
is no longer available.
How do I stop listening to authState(app.auth())
once I have signed in. Where does the unsubscribe logic go in an epic?