I spent 3 days for this problem, I need your help
I have a 2 problems about google social login in my Angular project.
Keeping user logged in after refresh (i used Google OAuth2)
when first rendering, i can't see login button:(
I solved first proble according to this link, but i solved first proble according to this link, The second problem still haunts me.
I think my project has problem which oninit function complete after templete rendering.
This code is my component.ts file.
export class NavbarComponent implements OnInit {
log : boolean
test : any
googleAuth: any
auth2 : gapi.auth2.GoogleAuth
constructor(
private ref : ChangeDetectorRef,
private http: HttpClient) { }
async ngOnInit() {
gapi.load('auth2', () => {
gapi.auth2.init({
client_id: 'MY_CLIENT_ID',
scope : 'email',
})
.then((data) => {
this.auth2 = data;
this.googleAuth = gapi.auth2.getAuthInstance();
this.log = this.handleAuthChange();
this.googleAuth.isSignedIn.listen(this.handleAuthChange);
})
})
}
signIn = () => {
this.auth2.signIn()
};
signOut = () => {
this.auth2.signOut();
};
handleAuthChange = () => {
return this.googleAuth.isSignedIn.get();
}
I want to make a login function use onlu one button so, i wrote template code like this.
<nav class="navbar-container">
<a routerLink="/" class="main-icon-brand">
<img src="../../assets/image/icon.png" alt="logo image" id="icon-image">
</a>
<a routerLink="/tutorial" class="each-item">
<span>Tutorial</span>
</a>
<a routerLink="/making" class="each-item">
<span>Making</span>
</a>
<a routerLink="/search" class="each-item">
<span>Search</span>
</a>
<div id="navbar-space"></div>
<div>
<div *ngIf="log === false">
<button (click)="signIn()" mat-icon-button color="warn">
<mat-icon>account_circle</mat-icon>
</button>
</div>
<div *ngIf="log === true">
<button (click)="signOut()" mat-icon-button color="warn">
<mat-icon>face</mat-icon>
</button>
</div>
</div>
</nav>
umm... i think, this has two solution
- blocking rendering template until finishing onInit
- i try rxjs observable but, my skill is low level so it donesn't work( maybe, i have wrong concept of rxjs)