在我的 Angular-Firebase 在线购物项目中,我曾经AuthGuard检查用户是否登录以访问./check-out其他链接,如下面的代码所示。得到一个错误,map因为Observable.User在下面的代码中没有被导入。使用最新版本的所有内容。
auth.service.ts
import { Observable } from 'rxjs';
import { Injectable } from '@angular/core';
import { AngularFireAuth } from '@angular/fire/auth';
import * as firebase from 'firebase';
@Injectable({
providedIn: 'root'
})
export class AuthService {
user$: Observable<firebase.User>;
constructor(private afAuth: AngularFireAuth) {
this.user$=afAuth.authState;
}
login(){
this.afAuth.auth.signInWithRedirect(new firebase.auth.GoogleAuthProvider())
}
logout(){
this.afAuth.auth.signOut()
}
}
Run Code Online (Sandbox Code Playgroud)
登录.component.ts
import { AuthService } from './../auth.service'
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: …Run Code Online (Sandbox Code Playgroud)