There should be no reason you cannot use the underlying Firebase API, as the Firebase App that's created by AngularFire2 is made available for injection.
You can use the injected app to access any methods of the auth()
(or storage()
) instances that are not exposed by AngularFire2.
For the purposes of an example, you could inject it into an app component like this:
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);
});
}
});
}
}
You don't have to use the auth
observable; you could also put the code into a promise chain using the promise returned by AngularFire2's auth.login
method.
As noted in the comments below, the GoogleAuthProvider
class is in the firebase.app
namespace (not the app instance). Also, as the current user is made available by AngularFire2 in the (confusingly named) auth
property of the FirebaseAuthState
, you don't need to inject the app instance to do what you want to do with the Google provider. You just need the firebase
import:
this.angularFire.auth.login({
email: "[email protected]",
password: "password",
})
.then((authState: FirebaseAuthState) => {
authState.auth.linkWithRedirect(new firebase.auth.GoogleAuthProvider());
});