Skip to content

Instantly share code, notes, and snippets.

@code-vagabond
Created February 3, 2018 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save code-vagabond/fff4b4b3e21a0cff5b274f2710e162b3 to your computer and use it in GitHub Desktop.
Save code-vagabond/fff4b4b3e21a0cff5b274f2710e162b3 to your computer and use it in GitHub Desktop.
/**
* Effect class for auth effects
*/
@Injectable()
export class AuthEffects {
constructor(private actions$: Actions,
private authApi: AuthApi,
private authUserApi: AuthUserApi,
private authStoreApi: AuthStoreService) {}
/** Effect Declarations **/
@Effect()
signIn$ = this.actions$
.ofType(AuthActionTypes.SIGN_IN)
.switchMap((action: SignInAction) => this.onSignIn(action));
/** Effect Handler **/
onSignIn(action: SignInAction): Observable<Action> {
return this.authApi
.getTokenUsingCredentials(
action.payload.username,
action.payload.password
)
.mergeMap((getTokenResponse: GetTokenResponse) => {
return [
tokenRefreshed(getTokenResponse), signedIn(),
// new RouterActions.Go({ path: ['/profile'] })
];
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment