我是Firebase的新手,但我想在当前的angular2项目中使用它。我使用Angularfire2卡住了电子邮件密码验证。据我了解API,你必须调用firebase.auth.Auth
对象的signInWithEmailAndPassword(email, password)
方法。不过,我不知道如何获得这个'Auth'的实例。 我确实发现一个example进行身份验证。但该示例不使用电子邮件/密码认证。我找不到任何关于如何以正确方式调用上述方法的示例。身份验证电子邮件/密码与Firebase sdk3和Angularfire2
我找到了一些JS实例。在那里,“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