AngularFire2에 의해 생성 된 Firebase App을 주입 할 수 있도록 기본 Firebase API를 사용할 수없는 이유가 없어야합니다.
삽입 된 앱을 사용하여 AngularFire2에 노출되지 않은 auth()
(또는 storage()
) 인스턴스의 모든 메소드에 액세스 할 수 있습니다. 예를 들어의 목적
,이 같은 응용 프로그램 구성 요소에 주입 수 : 당신은 auth
관찰을 사용할 필요가 없습니다
import { Component, Inject } from "@angular/core";
import { AngularFire, FirebaseApp } from "angularfire2";
import * as firebase from "firebase";
@Component({
selector: "app",
template: ...
})
export class AppComponent {
constructor(
// Inject AngularFire2:
private angularFire: AngularFire,
// Inject the Firebase App instance:
@Inject(FirebaseApp) private firebaseApp: firebase.app.App
) {
// Perform some sort of login.
...
angularFire.auth.subscribe((state) => {
// AngularFire2's auth observable will emit when the authentication
// state changes and if the state is non-null, there will be a
// current user. At this point, you should be able to do with the
// injected app what it was you were doing with the SDK.
if (state) {
var credential = firebase.auth
.GoogleAuthProvider
.credential(googleUser.getAuthResponse().id_token);
firebaseApp.auth()
.currentUser
.link(credential)
.then((user) => {
console.log("Anonymous account successfully upgraded", user);
})
.catch((error) => {
console.log("Error upgrading anonymous account", error);
});
}
});
}
}
; AngularFire2의 auth.login
메소드가 반환하는 약속을 사용하여 약속 체인에 코드를 삽입 할 수도 있습니다.
아래 설명에서 언급했듯이 GoogleAuthProvider
클래스는 firebase.app
네임 스페이스에 있습니다 (앱 인스턴스 아님). 또한 현재 사용자가 FirebaseAuthState
이라는 (혼동을 일으키는) auth
속성의 AngularFire2에서 제공되므로 Google 제공 업체를 통해 원하는 작업을 수행하기 위해 앱 인스턴스를 삽입 할 필요가 없습니다. firebase
이 필요합니다.
this.angularFire.auth.login({
email: "[email protected]",
password: "password",
})
.then((authState: FirebaseAuthState) => {
authState.auth.linkWithRedirect(new firebase.auth.GoogleAuthProvider());
});
앱의 인증 서비스에서 GoogleAuthProvider 클래스에 액세스 할 수있는 것 같지 않습니다. – DenimChicken
인스턴스를 네임 스페이스와 혼동하는 것 같습니다. 'firebase.auth.GoogleAuthProvider'를 시도하십시오 - 여기서'firebase'는 예제에서 가져온 네임 스페이스입니다. (그게 문제를 해결한다면'FirebaseApp'의 주입이 필요 없기 때문에 답을 다시 쓸 것입니다.) – cartant
'this.firebaseApp.auth()와 같은 계정을 업그레이드 할 수있었습니다. currentUser.linkWithRedirect (new firebase.auth.GoogleAuthProvider()); 올바른 방향으로 나를 가리켜 주셔서 감사합니다! – DenimChicken