Skip to content

Instantly share code, notes, and snippets.

@whisher
Created February 13, 2019 21:33
Show Gist options
  • Save whisher/2e98682709cddf4e2255a906a181f84d to your computer and use it in GitHub Desktop.
Save whisher/2e98682709cddf4e2255a906a181f84d to your computer and use it in GitHub Desktop.
import { Injectable } from '@angular/core';
import { select, Store } from '@ngrx/store';
import { Credentials } from '../../models';
import { State } from '../reducers';
import {
selectError,
selectLoading,
selectIsAuthenticated,
selectToken
} from '../selectors';
import { Login, Logout } from '../actions';
@Injectable({
providedIn: 'root'
})
export class AuthFacade {
error$ = this.store.pipe(select(selectError));
loading$ = this.store.pipe(select(selectLoading));
isAuthenticated$ = this.store.pipe(select(selectIsAuthenticated));
token$ = this.store.pipe(select(selectToken));
constructor(private store: Store<State>) {}
login(credentials: Credentials): void {
this.store.dispatch(new Login({ credentials }));
}
logout(): void {
this.store.dispatch(new Logout());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment