【发布时间】:2021-12-12 19:43:09
【问题描述】:
import { Injectable } from '@angular/core';
import { AngularFireAuth } from '@angular/fire/compat/auth';
import * as firebase from 'firebase/auth';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class AuthService {
user$:Observable<firebase.User> ;
constructor(private afAuth: AngularFireAuth) {
this.user$ = afAuth.authState;
}
login(){
this.afAuth.signInWithRedirect(new firebase.GoogleAuthProvider());
}
logout(){
this.afAuth.signOut();
}
}
我正在使用 angular 12 和 firebase 进行谷歌身份验证,但在 this.user$ = afAuth.authState; 附近出现错误; 键入'可观察' 不可分配给类型 'Observable'。 输入“用户 | null' 不可分配给类型“用户”。 类型“null”不能分配给类型“用户”
【问题讨论】:
标签: angular typescript firebase-authentication observable google-authentication