11# 5. User authentication
22
3- > AngularFire2 provides you an Observable for your Firebase Authentication
4- State via the ` AngularFireAuth ` module.
3+ ` AngularFireAuth.authState ` provides you an ` Observable<firebase.User> ` to monitor your application's authentication State.
54
6- AngularFireAuth's ` .auth ` object will return an initialized
7- ` firebase.auth.Auth ` instance, allowing you to log users in and out. [ See
5+ ` AngularFireAuth .auth` returns an initialized
6+ ` firebase.auth.Auth ` instance, allowing you to log users in, out, etc . [ See
87the Firebase docs for more information on what methods are availabile.] ( https://firebase.google.com/docs/reference/js/firebase.auth.Auth )
98
109** Example app:**
@@ -13,7 +12,8 @@ the Firebase docs for more information on what methods are availabile.](https://
1312import { Component } from ' @angular/core' ;
1413import { Observable } from ' rxjs/Observable' ;
1514import { AngularFireAuth } from ' angularfire2/auth' ;
16- import { GoogleAuthProvider , User as FirebaseUser } from ' firebase/auth' ;
15+ import { GoogleAuthProvider } from ' firebase/auth' ;
16+ import { User } from ' firebase' ;
1717
1818@Component ({
1919 selector: ' app-root' ,
@@ -25,7 +25,7 @@ import { GoogleAuthProvider, User as FirebaseUser } from 'firebase/auth';
2525})
2626export class AppComponent {
2727
28- user: Observable <FirebaseUser >;
28+ user: Observable <User >;
2929
3030 constructor (public afAuth : AngularFireAuth ) {
3131 this .user = afAuth .authState ;
@@ -53,17 +53,17 @@ Login with Facebook.
5353
5454``` cordova plugin add cordova-plugin-facebook4 --save --variable APP_ID="123456789" --variable APP_NAME="myApplication" ```
5555
56- 2- Use signInWithCredential login method
56+ 2- Use ` signInWithCredential ` method
5757
5858``` ts
59- console .log (" Facebook success: " + JSON .stringify (result ));
60- var provider = firebase .auth .FacebookAuthProvider .credential (result .authResponse .accessToken );
61-
62- firebase .auth () .signInWithCredential (provider )
63- .then ((success ) => {
64- console .log (" Firebase success: " + JSON .stringify (success ));
65- })
66- .catch ((error ) => {
67- console .log (" Firebase failure: " + JSON .stringify (error ));
68- });
59+ console .log (" Facebook success: " + JSON .stringify (result ));
60+ var provider = firebase .auth .FacebookAuthProvider .credential (result .authResponse .accessToken );
61+
62+ afAuth .auth .signInWithCredential (provider )
63+ .then ((success ) => {
64+ console .log (" Firebase success: " + JSON .stringify (success ));
65+ })
66+ .catch ((error ) => {
67+ console .log (" Firebase failure: " + JSON .stringify (error ));
68+ });
6969```
0 commit comments