Skip to content

Instantly share code, notes, and snippets.

@jhcao23
Last active January 13, 2018 20:55
Show Gist options
  • Save jhcao23/3feb4f38ce98303cb160f51ab94cc737 to your computer and use it in GitHub Desktop.
Save jhcao23/3feb4f38ce98303cb160f51ab94cc737 to your computer and use it in GitHub Desktop.
Effect dispatch multiple Actions
@Injectable()
export class AuthEffects {
@Effect()
LOGIN$ = this.actions$.ofType(LOGIN).pipe(
map((action: PayloadableAction<string>) => action.payload),
switchMap((code: string) =>
this.googleService.googleLogin(code).pipe(
mergeMap((response: HttpResponse<any>) => {
if (response.status === 200) {
const jwt: string = response.headers.get(NAME_HEADER_JWT);
const actions: AuthAction[] = [];
if (hasText(jwt)) {
actions.push(new GoogleLoginSuccess(jwt));
const fwt: string = response.headers.get(NAME_HEADER_JWT_FIREBASE);
if (hasText(fwt)) {
actions.push(new FirebaseLogin(fwt));
}
return (actions);
}
}
return ([new GoogleLoginFail(response)]);
}),
catchError(err => of(new GoogleLoginFail(err)))
)
)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment