I am trying to implement Google authentication in AngularJS 2
I followed this link
I have build an app, containing 4 components
- Header Component
- Login Component
- Detail Component
- App Component (root)
Login Component has the login page code. Hence i have included the following in login.component.html ->
<div class="g-signin2" data-onsuccess="onSignIn"></div>
Logout button is included in the Header component. The code is as follows:
header.component.html
<div>
<span class="log-out" (click)="signOut()"> Logout </span>
</div>
header.component.ts
constructor (private router:Router, private ngZone: NgZone){
gapi.load('auth2', function () {
gapi.auth2.init()
});
window['signOut'] = (user) => ngZone.run(() => this.signOut());
}
signOut() {
var auth2 = gapi.auth2.getAuthInstance();
auth2.signOut().then(function () {
console.log('User signed out.');
});
this.router.navigate(['']);
}
Once logout is successful, it will get navigated back to login page, address is '', which has been set in app-routing.module
When i logout, i get redirected to login page, but the Google sign button disappears. On refreshing it appears again
If i am missing something, please direct me!