2016-07-13 11 views
2

Firebaseを初めて使用しましたが、私は現在のangular2プロジェクトで使用したいと思います。私はAngularfire2を使ってEmail-Password-Authenticationに悩まされています。私がAPIを理解する限り、firebase.auth.AuthオブジェクトのsignInWithEmailAndPassword(email, password)メソッドを呼び出さなければなりません。私はこの「認証」のインスタンスを取得する方法はわかりませんが、 私は一般的に認証のためにexampleを見つけました。しかし、この例では電子メール/パスワード認証は使用していません。上記のメソッドを正しい方法で呼び出す方法の例は見つかりません。Firebase sdk3とAngularfire2の認証電子メール/パスワード

JS-Examplesが見つかりました。そこで、Authオブジェクトが何とか注入されます。これは私が試したように動作していないようです。これは私が(動作していない)、これまでに得たものである:

main.ts

bootstrap(AppComponent, [..., FIREBASE_PROVIDERS, 
defaultFirebase({ 
    apiKey: "<>", 
    authDomain: "<>", 
    databaseURL: "<>", 
    storageBucket: "<>", 
}),firebaseAuthConfig({ 
    provider: AuthProviders.Password, 
    method: AuthMethods.Password 
}), AuthService]) 
.catch(err => console.error(err)); 

auth.service.ts:

@Injectable() 
export class AuthService{ 

private _authState: FirebaseAuthState = null; 

constructor(private _fireAuth:FirebaseAuth, private _af:AngularFire, private _auth:Auth){ 
    _fireAuth.subscribe((state:FirebaseAuthState) =>{ 
     this._authState = state; 
    }); 
} 

get authenticated():boolean{ 
    return this._authState !== null; 
} 

get id(): string { 
    return this.authenticated ? this._authState.uid : ''; 
} 

signIn(email:string, password:string):Promise<User>{ 
    return this._auth.signInWithEmailAndPassword(email, password); 
} 
... 

私のアプリも起動しない - >エラーCannot resolve all parameters for 'AuthService'(FirebaseAuth, AngularFire, ?)this._af.auth().signInWithEmailAndPassword(email, password)を使用しようとすると、Typescriptコンパイラは次のように文句を言います。error TS2349: Cannot invoke an expression whose type lacks a call signature.コンパイラエラーを無視してプログラムを実行すると、エラーTypeError: this._af.auth is not a functionが発生します。

ありがとうございました!

#AskFirebase

答えて

2

まあ、私はまだsignInWithEmailAndPasswordメソッドを使用する方法を見つけるdidntの。私は電子メール/パスワードでログインすることができました。あなただけが使用できます

signIn(email:string, password:string){ 
    _fireAuth.login({ 
    email: email, 
    password: password 
    }); 
} 

ここで_fireAuthはFirebaseAuthタイプです。

関連する問題