|
|
@@ -31,12 +31,7 @@ export class FacebookLoginComponent implements OnInit { |
|
|
|
} |
|
|
|
|
|
|
|
ngAfterViewInit() { |
|
|
|
if (localStorage.getItem('FBUser') && localStorage.getItem('FBToken')) { |
|
|
|
this.user = JSON.parse(localStorage.getItem('FBUser')); |
|
|
|
this.token = localStorage.getItem('FBToken'); |
|
|
|
} else { |
|
|
|
this.setupFbLogin(); |
|
|
|
} |
|
|
|
this.setupFbLogin(); |
|
|
|
} |
|
|
|
|
|
|
|
ngOnInit() { |
|
|
@@ -48,9 +43,15 @@ export class FacebookLoginComponent implements OnInit { |
|
|
|
// Use the native implementation inside a real app! |
|
|
|
const { FacebookLogin } = Plugins; |
|
|
|
this.fbLogin = FacebookLogin; |
|
|
|
|
|
|
|
if (localStorage.getItem('FBUser') && localStorage.getItem('FBToken')) { |
|
|
|
this.user = JSON.parse(localStorage.getItem('FBUser')); |
|
|
|
this.getCurrentToken(); |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
this.hideAll = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
async login() { |
|
|
@@ -73,7 +74,7 @@ export class FacebookLoginComponent implements OnInit { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
async getCurrentToken() { |
|
|
|
async getCurrentToken() { |
|
|
|
const result = await this.fbLogin.getCurrentAccessToken(); |
|
|
|
|
|
|
|
if (result.accessToken) { |
|
|
@@ -91,12 +92,16 @@ export class FacebookLoginComponent implements OnInit { |
|
|
|
this.http.get(url).subscribe(res => { |
|
|
|
this.user = res; |
|
|
|
localStorage.setItem('FBUser', JSON.stringify(res)); |
|
|
|
}, err => { |
|
|
|
}, (err) => { |
|
|
|
console.log(JSON.stringify(err)); |
|
|
|
alert("Falied to fetch user data"); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
async logout() { |
|
|
|
await this.fbLogin.logout().then(() => { |
|
|
|
console.log("Logged Out"); |
|
|
|
}, (err) => alert(JSON.stringify(err))); |
|
|
|
this.user = null; |
|
|
|
this.token = null; |
|
|
|
localStorage.removeItem('FBUser'); |
|
|
|