Advertisement
Guest User

loginService

a guest
Jul 13th, 2017
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Injectable, Input, SimpleChanges } from '@angular/core';
  2. import { FacebookService, LoginResponse, InitParams, LoginOptions, LoginStatus } from 'ngx-facebook';
  3. import { BehaviorSubject } from 'rxjs/BehaviorSubject';
  4.  
  5. @Injectable()
  6.  
  7. export class LoginService {
  8.  
  9.     private connectionOn = new BehaviorSubject<boolean>(false);    
  10.     connectionOn$ = this.connectionOn.asObservable();
  11.     @Input() logResponse: LoginResponse;
  12.  
  13.     constructor(private fb: FacebookService) {
  14.  
  15.  
  16.         let initParams: InitParams = {
  17.             // access data
  18.         };
  19.  
  20.         fb.init(initParams);
  21.  
  22.     }
  23.  
  24.     private set isConnected(value: boolean) {
  25.         this.connectionOn.next(value);
  26.     }
  27.  
  28.     private get isConnected():boolean{
  29.         return this.connectionOn.getValue();
  30.     }
  31.  
  32.     login() {
  33.  
  34.         const loginOptions: LoginOptions = {
  35.             enable_profile_selector: true,
  36.             return_scopes: true,
  37.             scope: 'public_profile,user_likes,email,pages_show_list'
  38.         };
  39.  
  40.         this.fb.login()
  41.             .then((response: LoginResponse) => this.logResponse = response)
  42.             .catch((error: any) => console.error(error));
  43.     }
  44.  
  45.     ngOnChanges(changes: SimpleChanges) {
  46.         if (this.logResponse.status === 'connected') {
  47.             this.isConnected(true);
  48.         } else {
  49.             this.isConnected(false);
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement