Skip to content

Instantly share code, notes, and snippets.

@alanxone
Last active June 11, 2018 09:04
Show Gist options
  • Save alanxone/8ae603965e8d30e809e213e6b607fe2b to your computer and use it in GitHub Desktop.
Save alanxone/8ae603965e8d30e809e213e6b607fe2b to your computer and use it in GitHub Desktop.
NGRX Tutorial - Auth Service
// 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