1
1
# 5. User authentication
2
2
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.
5
4
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
8
7
the Firebase docs for more information on what methods are availabile.] ( https://firebase.google.com/docs/reference/js/firebase.auth.Auth )
9
8
10
9
** Example app:**
@@ -13,7 +12,8 @@ the Firebase docs for more information on what methods are availabile.](https://
13
12
import { Component } from ' @angular/core' ;
14
13
import { Observable } from ' rxjs/Observable' ;
15
14
import { AngularFireAuth } from ' angularfire2/auth' ;
16
- import { GoogleAuthProvider , User as FirebaseUser } from ' firebase/auth' ;
15
+ import { GoogleAuthProvider } from ' firebase/auth' ;
16
+ import { User } from ' firebase' ;
17
17
18
18
@Component ({
19
19
selector: ' app-root' ,
@@ -25,7 +25,7 @@ import { GoogleAuthProvider, User as FirebaseUser } from 'firebase/auth';
25
25
})
26
26
export class AppComponent {
27
27
28
- user: Observable <FirebaseUser >;
28
+ user: Observable <User >;
29
29
30
30
constructor (public afAuth : AngularFireAuth ) {
31
31
this .user = afAuth .authState ;
@@ -53,17 +53,17 @@ Login with Facebook.
53
53
54
54
``` cordova plugin add cordova-plugin-facebook4 --save --variable APP_ID="123456789" --variable APP_NAME="myApplication" ```
55
55
56
- 2- Use signInWithCredential login method
56
+ 2- Use ` signInWithCredential ` method
57
57
58
58
``` 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
+ });
69
69
```
0 commit comments