Last active
June 11, 2018 09:04
-
-
Save alanxone/8ae603965e8d30e809e213e6b607fe2b to your computer and use it in GitHub Desktop.
NGRX Tutorial - Auth Service
This file contains hidden or 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
// NGRX Complete Tutorial Without Pain (Angular6 / RxJS6) | |
// https://medium.com/@andrew.kao/ngrx-complete-tutorial-without-pain-angular6-rxjs6-5511b8cb8dac | |
import { Injectable } from '@angular/core'; | |
import { of, Observable, throwError } from 'rxjs'; | |
import { Authentication } from '(authentication model)'; | |
@Injectable() | |
export class AuthService { | |
constructor() {} | |
login(data: Authentication): Observable<string> { | |
// Do something you like to validate the credentials | |
// Eg, Call the API -> subscribe -> check -> hanlde error ... etc | |
if (!valid) { | |
throwError('Invalid credentials'); | |
} | |
// Pretending all good, return the username | |
return of('Sun,Yat-Sen'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment