Last active
January 13, 2018 20:55
-
-
Save jhcao23/3feb4f38ce98303cb160f51ab94cc737 to your computer and use it in GitHub Desktop.
Effect dispatch multiple Actions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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