Created
January 28, 2020 16:32
Capacitor Angular Ionic Fb login - Home Page
This file contains 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
import { Component } from '@angular/core'; | |
import { Plugins } from '@capacitor/core'; | |
import { Router, ActivatedRoute } from '@angular/router'; | |
@Component({ | |
selector: 'app-home', | |
templateUrl: 'home.page.html', | |
styleUrls: ['home.page.scss'], | |
}) | |
export class HomePage { | |
logininfo: any; | |
user: any; | |
constructor(private route: ActivatedRoute, private router: Router) { | |
this.route.queryParams.subscribe(params => { | |
if (params && params.userinfo) { | |
this.logininfo = JSON.parse(params.userinfo); | |
} | |
}); | |
} | |
ionViewWillEnter() { | |
this.getUserInfo(); | |
} | |
async signOut(): Promise<void> { | |
await Plugins.FacebookLogin.logout(); | |
this.router.navigate(['/login']); | |
} | |
async getUserInfo() { | |
const response = await fetch(`https://graph.facebook.com/${this.logininfo.userId}?fields=id,name,gender,link,picture&type=large&access_token=${this.logininfo.token}`); | |
const myJson = await response.json(); | |
this.user = myJson | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment