저는 신입생 angularfire2입니다. 현재 인증을 시도하고 사용자에게 이미 로그인 또는 로그 아웃했음을 알리고 있습니다. 현재 버전은 angularfire2": "^5.0.0-rc.4
입니다. this link에서 예제를 발견했지만 어떻게 작동하는지 잘 모르겠습니다. 내가해야 할 일은 사용자에게 "you are not logged in, please log in first"
과 같은 것을 알려주고 그들이 로그인 할 때 "you are logged in"
과 같을 것입니다 (메시지에 로그인하지 않은 것은 false
/표시되지 않습니다).각도, 사용자가 로그인했는지 여부를 알려주는 방법은 무엇입니까?
//auth.service.ts
login() {
this.afAuth.auth.signInWithPopup(new firebase.auth.GoogleAuthProvider());
}
private currentUser: firebase.User = null;
isLogin() {
if (this.currentUser == null) {
return false;
} else {
return true;
}
}
logOut() {
this.afAuth.auth.signOut();
console.log(this.afAuth.authState);
}
//app.component.ts
disableBtn: boolean = false;
disableBtn2: boolean = false;
CallLogin() {
this.AuthService.login();
}
isLoggedIn() {
return this.AuthService.isLogin();
}
CallLogOut() {
this.AuthService.logOut();
}
<!--app.component.html-->
<div *ngIf="isLoggedIn() || !disableBtn2">
<p>you are not logged in</p>
<a href="#" (click)="CallLogin(); disableBtn=!disableBtn">LOGIN</li>
<div *ngIf="isLoggedIn() || !disableBtn">
<p>you are logged in</p>
<a href="#" (click)="CallLogOut(); disableBtn2=!disableBtn2">LOG OUT</a>
</div>
누군가 날이 제발 알아내는 데 도움이 수 있습니까?
이 [답변] (https://stackoverflow.com/questions/47399252/angularfire2-auth-state-on-page-reload-check-user-logged-in/47399801#47399801)을 확인하십시오. – Hareesh