For a specific scenario, I need to login as an admin in one case and as a regular user in another.
signIn$ = createEffect(() =>
this.actions$.pipe(
ofType(AuthActions.signInRequest),
exhaustMap(({ variables, redirectTo, hasAdmin }) => hasAdmin ?
this.authService.signInAdmin(variables) :
this.authService.signIn(variables).pipe(
map((response) => {
//... AuthActions.signInSuccess(response.token)
}),
catchError(() => of(AuthActions.signInFailure()))
)
)
)
);
Even though the API response is the same for both cases, I encountered the following error:
Type 'Observable<FetchResult<SignInAdmin, Record<string, any>, Record<string, any>> | FetchResult<SignIn, Record<string, any>, Record<...>>>' is not assignable to type 'EffectResult'. Type 'Observable<FetchResult<SignInAdmin, Record<string, any>, Record<string, any>> | FetchResult<SignIn, Record<string, any>, Record<...>>>' is not assignable to type 'Observable'. Type 'FetchResult<SignInAdmin, Record<string, any>, Record <string, any>> | FetchResult<SignIn, Record<string, any>, Record<string, any>>' is not assignable to type 'Action'.
Property 'type' is missing in type 'FetchResult<SignInAdmin, Record<string, any>, Record<string, any>>' but required in type 'Action'.ts(2322) models.d.ts(2, 5): 'type' is declared here.
effect_creator.d.ts(42, 161): The expected type comes from the return type of this signature.