firebaseを使用してangular2のauthオブジェクトにアクセスしようとしていますが、混乱してしまいました。コンソールでユーザー認証資格情報を確認できますが、認証変数はnullと思われます。AngularFire2のAuthオブジェクトへのアクセス
app.component.ts
import { Component } from '@angular/core';
import { AngularFire, FirebaseListObservable } from 'angularfire2';
import { AuthProviders, AuthMethods } from 'angularfire2';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app works!';
constructor(public af: AngularFire) {
this.af.auth.subscribe(auth => console.log(auth)); //nothing in the console
console.log(this.af.auth); // shows AngularFireAuth object with user credentials but says it is private
}
login() {
console.log("logging in...");
this.af.auth.login({
provider: AuthProviders.Google,
method: AuthMethods.Popup,
});
}
}
app.component.html
<div *ngIf="auth">You are logged in</div>
<div *ngIf="!auth">Please log in</div>
auth
変数がconsole.log(this.af.auth);
は、ユーザーの資格情報を示すため、唯一されていてもヌルであるように思われますPlease log in
がhtmlに表示されます。
あなたはコンポーネントloginメソッドを呼び出し、それの後にチェックがありますか?例を参照してください。 – ranakrunal9
私は前と同じような靴を着ていました。これが、コミュニティが認証状態を管理するためのドキュメントを提案した理由です。 https://github.com/angular/angularfire2/issues/343 –