Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Injectable } from "@angular/core";
- import { AngularFire, AuthProviders, AuthMethods, FirebaseListObservable, FirebaseObjectObservable } from 'angularfire2';
- import { UserModel } from '../users/models/user.model';
- @Injectable()
- export class AuthenticationService {
- public displayName: string;
- public userKey: string;
- public user: UserModel;
- constructor(public af: AngularFire) {
- this.af.auth.subscribe(
- (auth) => {
- if (auth != null) {
- this.user = this.af.database.object('users/' + auth.uid);
- this.userKey = auth.uid;
- }
- });
- }
- logout() {
- return this.af.auth.logout();
- }
- loginWithEmail(email, password) {
- return this.af.auth.login({
- email: email,
- password: password,
- },
- {
- provider: AuthProviders.Password,
- method: AuthMethods.Password,
- });
- }
- }
- import { Injectable } from '@angular/core';
- import { Router } from '@angular/router';
- import { AngularFire, FirebaseListObservable, FirebaseObjectObservable } from 'angularfire2';
- import { AuthenticationService } from '../authentication/authentication.service';
- import { CustomerModel } from './models/customer.model';
- @Injectable()
- export class CustomersService {
- customersRef: string = '/customers/';
- customer: any;
- usersCustomerId: string;
- constructor(
- private af: AngularFire,
- private authService: AuthenticationService,
- private router: Router) { }
- getAllCustomers(): FirebaseListObservable<CustomerModel[]> {
- this.usersCustomerId = this.authService.userKey;
- console.log(this.usersCustomerId);
- return this.af.database.list(this.customersRef, {
- query: {
- orderByChild: 'uid',
- equalTo: this.usersCustomerId
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement