Here is my button element:
<div class="dialog"><div class="btn btn-warning" *ngIf="!user" href="#" (click)="signInWithGoogle()">{{label}}<img src="{{img}}"/></div>
</div>
<div class="dialog" *ngIf="user"><div class="btn btn-warning" href="#" (click)="signOut()">{{label}}<img src="{{img}}" alt="{{alt}}"/></div>
</div>
Here is button.ts
public userDetails: any;
ngOnInit() {
this.authService.authState.subscribe(user => {
this.user = user;
});
const storage = localStorage.getItem('google_auth');
if (storage) {
this.userDetails = JSON.parse(storage);
} else {
this.signOut();
}
}
googleLoginOptions = {
scope: 'profile email'
};
signInWithGoogle() {
this.authService.signIn(GoogleLoginProvider.PROVIDER_ID,this.googleLoginOptions).then((data) => {
localStorage.setItem('google_auth', JSON.stringify(data));
this.router.navigateByUrl('/panel').then();
});
}
signOut(): void {
localStorage.removeItem('google_auth');
this.router.navigateByUrl('/').then(this.refreshGoogleToken);
}
refreshGoogleToken(): void {
this.authService.refreshAuthToken(GoogleLoginProvider.PROVIDER_ID);
}
Once the session is logged out, the sign up button does not get rendered and I have to refresh to log in.