-
Notifications
You must be signed in to change notification settings - Fork 2.2k

Description
Version info
Angular:
4.0.2
Firebase:
3.9.0
AngularFire:
4.0.0-rc.0
Other (e.g. Ionic/Cordova, Node, browser, operating system):
Cordova CLI: 7.0.0
Ionic Framework Version: 3.1.1
Ionic CLI Version: 2.2.3
Ionic App Lib Version: 2.2.1
Ionic App Scripts Version: 1.3.7
ios-deploy version: 1.8.6
ios-sim version: 5.0.8
OS: macOS Sierra
Node Version: v6.10.1
Xcode version: Xcode 8.2.1 Build version 8C1002
How to reproduce these conditions
use below code in ionic v2 starter app:
import { Component } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { AngularFireAuth } from 'angularfire2/auth';
import * as firebase from 'firebase/app';
@Component({
selector: 'app-root',
template: `
<div> {{ (user | async)?.uid }} </div>
<button (click)="login()">Login</button>
<button (click)="logout()">Logout</button>
`,
})
export class AppComponent {
user: Observable<firebase.User>;
constructor(public afAuth: AngularFireAuth) {
this.user = afAuth.authState;
}
login() {
this.afAuth.auth.signInWithPopup(new firebase.auth.GoogleAuthProvider());
}
logout() {
this.afAuth.auth.signOut();
}
}
Steps to set up and reproduce
Follow the steps as mention in this repo readme document #5. User authentication
Debug output
** Errors in the JavaScript console **
Runtime Error
Uncaught (in promise): Error: No provider for AngularFireAuth!
Same error occurs when used with this Using AngularFire2 with Ionic 2 readme document
import { Observable } from 'rxjs/Observable';
import { Injectable } from '@angular/core';
import { AngularFireAuth } from 'angularfire2/auth';
// Do not import from 'firebase' as you'll lose the tree shaking benefits
import * as firebase from 'firebase/app';
import { Platform } from 'ionic-angular';
import { Facebook } from 'ionic-native';
@Injectable()
export class AuthService {
private authState: Observable<firebase.User>;
private currentUser: firebase.User;
constructor(public afAuth: AngularFireAuth) {
this.authState = afAuth.authState;
afAuth.subscribe((user: firebase.User) => {
this.currentUser = user;
});
}
get authenticated(): boolean {
return this.currentUser !== null;
}
signInWithFacebook(): firebase.Promise<FirebaseAuthState> {
if (this.platform.is('cordova')) {
return Facebook.login(['email', 'public_profile']).then(res => {
const facebookCredential = firebase.auth.FacebookAuthProvider.credential(res.authResponse.accessToken);
return this.afAuth.auth.signInWithCredential(facebookCredential);
});
} else {
return this.afAuth.auth.signInWithPopup(new firebase.auth.FacebookAuthProvider());
}
}
signOut(): void {
this.afAuth.signOut();
}
displayName(): string {
if (this.currentUser !== null) {
return this.currentUser.facebook.displayName;
} else {
return '';
}
}
}
Please review looks like the document is missing some imports/exports.