import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { User } from 'src/app/model/user/User';
import { AngularFireAuth } from '@angular/fire/compat/auth';
import firebase from 'firebase/app'; // Notice the change here
@Injectable({
providedIn: 'root'
})
export class AuthService {
constructor(private auth: AngularFireAuth) { }
login(email: string, password: string): Observable<User> {
return new Observable<User>(observer => {
this.auth.setPersistence(firebase.auth.Auth.Persistence.LOCAL).then(() => {
this.auth.signInWithEmailAndPassword(email, password).then((firebaseUser:
firebase.auth.UserCredential) => {
observer.next({ email, id: firebaseUser.user.uid });
observer.complete();
}).catch(error => {
observer.error(error);
observer.complete();
});
});
});
}
}
`在第一个默认值上,我收到此错误:属性“默认”在类型“typeof import(”(文件夹目录)/node_modules/firebase/app/dist/app/index”)上不存在。ts(2339)
在第二个默认值上,我收到此错误:命名空间'“(文件夹目录)/node_modules/firebase/app/dist/app/index”'没有导出成员'default'.ts(2694)
我尝试了所有类型的导入,但仍然收到此错误`
您正在尝试将 firebase 作为默认导入导入,但您不能这样做,您需要将其作为命名导入导入。
像这样导入
import * as firebase from 'firebase/app';
不是
import firebase from 'firebase/app';