@angular/fire 7.5.0 → 7.6.0-canary.34e89a4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/README.md +95 -74
  2. package/analytics/is-analytics-supported-factory.d.ts +4 -0
  3. package/bundles/angular-fire-analytics.umd.js +41 -31
  4. package/bundles/angular-fire-analytics.umd.js.map +1 -1
  5. package/bundles/angular-fire-app-check.umd.js +14 -18
  6. package/bundles/angular-fire-app-check.umd.js.map +1 -1
  7. package/bundles/angular-fire-app.umd.js +14 -18
  8. package/bundles/angular-fire-app.umd.js.map +1 -1
  9. package/bundles/angular-fire-auth-guard.umd.js +5 -7
  10. package/bundles/angular-fire-auth-guard.umd.js.map +1 -1
  11. package/bundles/angular-fire-auth.umd.js +64 -68
  12. package/bundles/angular-fire-auth.umd.js.map +1 -1
  13. package/bundles/angular-fire-compat-analytics.umd.js +11 -13
  14. package/bundles/angular-fire-compat-analytics.umd.js.map +1 -1
  15. package/bundles/angular-fire-compat-auth-guard.umd.js +6 -8
  16. package/bundles/angular-fire-compat-auth-guard.umd.js.map +1 -1
  17. package/bundles/angular-fire-compat-auth.umd.js +11 -13
  18. package/bundles/angular-fire-compat-auth.umd.js.map +1 -1
  19. package/bundles/angular-fire-compat-database.umd.js +9 -11
  20. package/bundles/angular-fire-compat-database.umd.js.map +1 -1
  21. package/bundles/angular-fire-compat-firestore.umd.js +9 -11
  22. package/bundles/angular-fire-compat-firestore.umd.js.map +1 -1
  23. package/bundles/angular-fire-compat-functions.umd.js +9 -11
  24. package/bundles/angular-fire-compat-functions.umd.js.map +1 -1
  25. package/bundles/angular-fire-compat-messaging.umd.js +8 -10
  26. package/bundles/angular-fire-compat-messaging.umd.js.map +1 -1
  27. package/bundles/angular-fire-compat-performance.umd.js +8 -10
  28. package/bundles/angular-fire-compat-performance.umd.js.map +1 -1
  29. package/bundles/angular-fire-compat-remote-config.umd.js +9 -11
  30. package/bundles/angular-fire-compat-remote-config.umd.js.map +1 -1
  31. package/bundles/angular-fire-compat-storage.umd.js +8 -10
  32. package/bundles/angular-fire-compat-storage.umd.js.map +1 -1
  33. package/bundles/angular-fire-compat.umd.js +13 -15
  34. package/bundles/angular-fire-compat.umd.js.map +1 -1
  35. package/bundles/angular-fire-database.umd.js +59 -67
  36. package/bundles/angular-fire-database.umd.js.map +1 -1
  37. package/bundles/angular-fire-firestore-lite.umd.js +50 -54
  38. package/bundles/angular-fire-firestore-lite.umd.js.map +1 -1
  39. package/bundles/angular-fire-firestore.umd.js +67 -71
  40. package/bundles/angular-fire-firestore.umd.js.map +1 -1
  41. package/bundles/angular-fire-functions.umd.js +15 -19
  42. package/bundles/angular-fire-functions.umd.js.map +1 -1
  43. package/bundles/angular-fire-messaging.umd.js +33 -23
  44. package/bundles/angular-fire-messaging.umd.js.map +1 -1
  45. package/bundles/angular-fire-performance.umd.js +17 -21
  46. package/bundles/angular-fire-performance.umd.js.map +1 -1
  47. package/bundles/angular-fire-remote-config.umd.js +47 -37
  48. package/bundles/angular-fire-remote-config.umd.js.map +1 -1
  49. package/bundles/angular-fire-storage.umd.js +27 -31
  50. package/bundles/angular-fire-storage.umd.js.map +1 -1
  51. package/bundles/angular-fire.umd.js +16 -59
  52. package/bundles/angular-fire.umd.js.map +1 -1
  53. package/compat/firestore/interfaces.d.ts +4 -4
  54. package/core.d.ts +1 -12
  55. package/docs/analytics.md +67 -0
  56. package/docs/app-check.md +53 -0
  57. package/docs/auth.md +165 -0
  58. package/docs/{analytics → compat/analytics}/getting-started.md +2 -0
  59. package/docs/{auth → compat/auth}/getting-started.md +2 -0
  60. package/docs/{auth → compat/auth}/router-guards.md +2 -0
  61. package/docs/{emulators → compat/emulators}/emulators.md +2 -0
  62. package/docs/{firestore → compat/firestore}/collections.md +2 -0
  63. package/docs/{firestore → compat/firestore}/documents.md +2 -0
  64. package/docs/{firestore → compat/firestore}/offline-data.md +2 -0
  65. package/docs/{firestore → compat/firestore}/querying-collections.md +2 -0
  66. package/docs/{functions → compat/functions}/functions.md +2 -0
  67. package/docs/{messaging → compat/messaging}/messaging.md +2 -0
  68. package/docs/{performance → compat/performance}/getting-started.md +2 -0
  69. package/docs/{remote-config → compat/remote-config}/getting-started.md +2 -0
  70. package/docs/{rtdb → compat/rtdb}/lists.md +2 -0
  71. package/docs/{rtdb → compat/rtdb}/objects.md +2 -0
  72. package/docs/{rtdb → compat/rtdb}/querying-lists.md +2 -0
  73. package/docs/{storage → compat/storage}/storage.md +2 -0
  74. package/docs/compat.md +70 -0
  75. package/docs/database.md +175 -0
  76. package/docs/deploy/getting-started.md +2 -2
  77. package/docs/firestore.md +148 -0
  78. package/docs/functions.md +52 -0
  79. package/docs/images/analytics-illo_1x.png +0 -0
  80. package/docs/images/auth-illo_1x.png +0 -0
  81. package/docs/images/cloud-messaging-illo_1x.png +0 -0
  82. package/docs/images/database-illo_1x.png +0 -0
  83. package/docs/images/firestore-illo_1x.png +0 -0
  84. package/docs/images/functions-illo_1x.png +0 -0
  85. package/docs/images/hosting-illo_1x.png +0 -0
  86. package/docs/images/performance-illo_1x.png +0 -0
  87. package/docs/images/reCAPTCHA-logo@1x.png +0 -0
  88. package/docs/images/remote-config-illo_1x.png +0 -0
  89. package/docs/images/storage-illo_1x.png +0 -0
  90. package/docs/install-and-setup.md +39 -86
  91. package/docs/install-firebase-tools.md +78 -0
  92. package/docs/messaging.md +25 -0
  93. package/docs/performance.md +57 -0
  94. package/docs/remote-config.md +53 -0
  95. package/docs/storage.md +90 -0
  96. package/docs/universal/cloud-functions.md +27 -6
  97. package/docs/universal/getting-started.md +9 -134
  98. package/esm2015/analytics/analytics.module.js +7 -6
  99. package/esm2015/analytics/is-analytics-supported-factory.js +16 -0
  100. package/esm2015/analytics/overrides.js +3 -3
  101. package/esm2015/compat/firestore/interfaces.js +1 -1
  102. package/esm2015/core.js +3 -45
  103. package/esm2015/messaging/is-messaging-supported-factory.js +16 -0
  104. package/esm2015/messaging/messaging.module.js +7 -6
  105. package/esm2015/messaging/overrides.js +3 -3
  106. package/esm2015/remote-config/is-remote-config-supported-factory.js +16 -0
  107. package/esm2015/remote-config/overrides.js +3 -3
  108. package/esm2015/remote-config/remote-config.module.js +7 -6
  109. package/fesm2015/angular-fire-analytics.js +21 -7
  110. package/fesm2015/angular-fire-analytics.js.map +1 -1
  111. package/fesm2015/angular-fire-app-check.js.map +1 -1
  112. package/fesm2015/angular-fire-app.js.map +1 -1
  113. package/fesm2015/angular-fire-auth-guard.js.map +1 -1
  114. package/fesm2015/angular-fire-auth.js.map +1 -1
  115. package/fesm2015/angular-fire-compat-analytics.js.map +1 -1
  116. package/fesm2015/angular-fire-compat-auth-guard.js.map +1 -1
  117. package/fesm2015/angular-fire-compat-auth.js.map +1 -1
  118. package/fesm2015/angular-fire-compat-database.js +1 -1
  119. package/fesm2015/angular-fire-compat-database.js.map +1 -1
  120. package/fesm2015/angular-fire-compat-firestore.js +1 -1
  121. package/fesm2015/angular-fire-compat-firestore.js.map +1 -1
  122. package/fesm2015/angular-fire-compat-functions.js.map +1 -1
  123. package/fesm2015/angular-fire-compat-messaging.js.map +1 -1
  124. package/fesm2015/angular-fire-compat-performance.js.map +1 -1
  125. package/fesm2015/angular-fire-compat-remote-config.js.map +1 -1
  126. package/fesm2015/angular-fire-compat-storage.js.map +1 -1
  127. package/fesm2015/angular-fire-compat.js.map +1 -1
  128. package/fesm2015/angular-fire-database.js.map +1 -1
  129. package/fesm2015/angular-fire-firestore-lite.js.map +1 -1
  130. package/fesm2015/angular-fire-firestore.js.map +1 -1
  131. package/fesm2015/angular-fire-functions.js.map +1 -1
  132. package/fesm2015/angular-fire-messaging.js +21 -7
  133. package/fesm2015/angular-fire-messaging.js.map +1 -1
  134. package/fesm2015/angular-fire-performance.js.map +1 -1
  135. package/fesm2015/angular-fire-remote-config.js +22 -8
  136. package/fesm2015/angular-fire-remote-config.js.map +1 -1
  137. package/fesm2015/angular-fire-storage.js.map +1 -1
  138. package/fesm2015/angular-fire.js +3 -45
  139. package/fesm2015/angular-fire.js.map +1 -1
  140. package/messaging/is-messaging-supported-factory.d.ts +4 -0
  141. package/package.json +9 -10
  142. package/remote-config/is-remote-config-supported-factory.d.ts +4 -0
  143. package/schematics/deploy/actions.js +8 -3
  144. package/schematics/deploy/builder.js +2 -2
  145. package/schematics/firebaseTools.js +4 -2
  146. package/schematics/setup/index.js +58 -29
  147. package/schematics/setup/prompts.js +18 -46
  148. package/schematics/utils.js +32 -28
  149. package/docs/ionic/authentication.md +0 -104
  150. package/docs/ionic/cli.md +0 -218
  151. package/docs/ionic/v2.md +0 -531
  152. package/docs/ionic/v3.md +0 -705
  153. package/schematics/setup/ssr.js +0 -100
  154. package/schematics/setup/static.js +0 -78
package/docs/ionic/v3.md DELETED
@@ -1,705 +0,0 @@
1
- # Using AngularFire with Ionic 3
2
-
3
- This tutorial provides a walkthrough of integrating AngularFire Authentication with Ionic 3 /Angular 4+.
4
- The below setup has been tested on Windows 10 and macOS Sierra, but it should be same for Linux.
5
-
6
- Note: - If you're working with Ionic2 and Angular2.0, then you should refer to **Auth-with-Ionic2** tutorial
7
- [here](https://github.com/angular/angularfire2/blob/master/docs/Auth-with-Ionic2.md)
8
-
9
- Ensure that you're executing these commands as **Administrator** on Windows and **sudo** on Mac/Linux if you get any permission errors.
10
-
11
- This tutorial uses **Facebook** as the sign-in provider. After completing this tutorial, you should be able to configure
12
- other sign-in providers like **Twitter**, **Google** on your own.
13
-
14
- ### Prerequisites
15
- The first step is to ensure you have latest version of **Node** installed.
16
- You can get the latest version from [nodejs.org](https://nodejs.org).
17
- This will install both `node` and `npm`.
18
-
19
- After installing node, check the version by executing the following command in your prompt window:
20
-
21
- ```bash
22
-
23
- $ node -v
24
- v6.10.2
25
- ```
26
-
27
- As of this writing, this is the most stable version. If you're not on this version,
28
- please upgrade yourself to latest stable version by installing node from [nodejs.org](https://nodejs.org).
29
-
30
- Check your npm version by executing the following command:
31
- ```bash
32
-
33
- $ npm -v
34
- 3.10.10
35
- ```
36
- Install the Angular CLI, which will be used to build our Angular project and install Angular version 4 or later.
37
-
38
- ```bash
39
- $ npm install -g @angular/cli
40
- ```
41
- Check your angular version by executing the following command:
42
-
43
- ```bash
44
- $ ng -v
45
-
46
- @angular/cli: 1.0.0
47
- node: 6.10.2
48
- os: win32 x64
49
- ```
50
-
51
- **_Your Application code sits on top of Ionic Framework and the Ionic Framework sits on top of Cordova._**
52
-
53
- Let's get them installed globally, so that all projects can use them.
54
-
55
- Execute the following commands.
56
-
57
- ```bash
58
-
59
- $ npm install -g cordova ionic
60
- ```
61
-
62
- Once the above command is executed successfully, check the versions of cordova and ionic:
63
-
64
- ```bash
65
- $ cordova -v
66
- 7.0.1
67
-
68
- $ ionic -v
69
- 3.4.0
70
- ```
71
-
72
- You're all set to create your app with Ionic framework.
73
-
74
- To create your app, change into the directory where you want your app to reside and execute the following command:
75
-
76
- ```bash
77
- $ ionic start auth-ng4-ionic3-af2 blank
78
- ```
79
-
80
- >The command ionic start will create the project with name "auth-ng4-ionic3-af2" using "blank" template.
81
-
82
- Change to the project directory, which was just created with the above command.
83
-
84
- ```
85
- $ ionic info
86
-
87
- global packages:
88
-
89
- @ionic/cli-utils : 1.4.0
90
- Cordova CLI : 7.0.1
91
- Ionic CLI : 3.4.0
92
-
93
- local packages:
94
-
95
- @ionic/app-scripts : 1.3.12
96
- @ionic/cli-plugin-cordova : 1.4.0
97
- @ionic/cli-plugin-ionic-angular : 1.3.1
98
- Cordova Platforms : none
99
- Ionic Framework : ionic-angular 3.5.0
100
-
101
- System:
102
-
103
- Node : v8.1.2
104
- OS : Windows 10
105
- Xcode : not installed
106
- ios-deploy : not installed
107
- ios-sim : not installed
108
- npm : 5.0.4
109
- ```
110
- You need to ensure you've got Ionic Framework Version 3, as shown above.
111
-
112
- Alternatively you can open `package.json` to ensure you've got the following Angular and Ionic versions:
113
-
114
- ```json
115
- "dependencies": {
116
- "@angular/common": "4.1.3",
117
- "@angular/compiler": "4.1.3",
118
- "@angular/compiler-cli": "4.1.3",
119
- "@angular/core": "4.1.3",
120
- "@angular/forms": "4.1.3",
121
- "@angular/http": "4.1.3",
122
- "@angular/platform-browser": "4.1.3",
123
- "@angular/platform-browser-dynamic": "4.1.3",
124
- "@ionic-native/core": "3.12.1",
125
- "@ionic-native/splash-screen": "3.12.1",
126
- "@ionic-native/status-bar": "3.12.1",
127
- "@ionic/storage": "2.0.1",
128
- "ionic-angular": "3.6.0",
129
- "ionicons": "3.0.0",
130
- "rxjs": "5.4.0",
131
- "sw-toolbox": "3.6.0",
132
- "zone.js": "0.8.12"
133
- },
134
- "devDependencies": {
135
- "@ionic/app-scripts": "1.3.12",
136
- "@ionic/cli-plugin-ionic-angular": "1.3.1",
137
- "typescript": "~2.3.4"
138
- }
139
-
140
- ```
141
-
142
- If not, replace them to match above. These are the latest as of writing this tutorial.
143
-
144
- To start your app, execute the following command:
145
-
146
- ```bash
147
-
148
- $ ionic serve
149
- ```
150
- If everything is installed correctly, the app should open your browser with the dev server running at the following url
151
- **`http://localhost:8100`** and will display default home page.
152
-
153
- ### Configuring AngularFire and Firebase
154
-
155
- Install the required packages in your project directory:
156
-
157
- ```ts
158
-
159
- $ npm install angularfire2 firebase promise-polyfill --save
160
-
161
- ```
162
-
163
- _This should add angularfire2, promise-polyfill and firebase entry in your project's package.json file as dependencies. Something similar to:_
164
-
165
- ```
166
- "angularfire2": "^4.0.0-rc.1",
167
- "firebase": "^4.1.3",
168
- "promise-polyfill": "^6.0.2",
169
- ```
170
-
171
- As the Angularfire2 v5+ rc10 requires rxjs6, you need to install rxjs-compat for angular version < 6.0:
172
- ```
173
- npm install rxjs@6 rxjs-compat@6 promise-polyfill --save
174
- ```
175
- ### Setup @NgModule
176
-
177
- Open your project in your favourite editor and open the `app.module.ts` file, under `src/app`
178
- and add the following three entries.
179
-
180
- 1) Import AngularFireModule and AngularFireDatabaseModule at top.
181
-
182
- 2) Define your firebaseConfig constant.
183
-
184
- 3) Initialize your app, by adding AngularFireModule and AngularFireAuthModule in the "imports" array in @NgModule
185
-
186
- 4) Also, add AngularFireDatabase in the "providers" array in @NgModule
187
-
188
- your `app.module.ts` file should look something like this.
189
-
190
- ```typescript
191
-
192
- import { BrowserModule } from '@angular/platform-browser';
193
- import { ErrorHandler, NgModule } from '@angular/core';
194
- import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
195
- import { SplashScreen } from '@ionic-native/splash-screen';
196
- import { StatusBar } from '@ionic-native/status-bar';
197
-
198
- import { MyApp } from './app.component';
199
- import { HomePage } from '../pages/home/home';
200
-
201
- import { AngularFireModule } from '@angular/fire/compat';
202
- import { AngularFireDatabaseModule, AngularFireDatabase } from '@angular/fire/compat/database';
203
- import { AngularFireAuthModule } from '@angular/fire/compat/auth';
204
-
205
- export const firebaseConfig = {
206
- apiKey: "xxxxxxxxxx",
207
- authDomain: "your-domain-name.firebaseapp.com",
208
- databaseURL: "https://your-domain-name.firebaseio.com",
209
- storageBucket: "your-domain-name.appspot.com",
210
- messagingSenderId: '<your-messaging-sender-id>'
211
- };
212
-
213
- @NgModule({
214
- declarations: [
215
- MyApp,
216
- HomePage
217
- ],
218
- imports: [
219
- BrowserModule,
220
- IonicModule.forRoot(MyApp),
221
- AngularFireModule.initializeApp(firebaseConfig),
222
- AngularFireDatabaseModule,
223
- AngularFireAuthModule
224
- ],
225
- bootstrap: [IonicApp],
226
- entryComponents: [
227
- MyApp,
228
- HomePage
229
- ],
230
- providers: [
231
- StatusBar,
232
- SplashScreen,
233
- AngularFireDatabase,
234
- {provide: ErrorHandler, useClass: IonicErrorHandler}
235
- ]
236
- })
237
- export class AppModule {}
238
-
239
- ```
240
-
241
- ### Inject AngularFire and Bind it to List
242
-
243
- Now inject AngularFireDatabase in your component. Open your `home.ts` by going into `src/pages/home/home.ts` and make the
244
- following changes:
245
-
246
- >1) Import "AngularFireDatabase" at the top of your component.
247
-
248
- >2) Inject your AngularFireDatabase dependency in the constructor.
249
-
250
- >3) Call the list method on AngularFireDatabase object.
251
-
252
- Your `home.ts` file should look like this:
253
-
254
- ```typescript
255
-
256
- import { Component } from '@angular/core';
257
- import { NavController } from 'ionic-angular';
258
-
259
- import { AngularFireDatabase } from '@angular/fire/compat/database';
260
- import { Observable } from 'rxjs/Observable';
261
-
262
- @Component({
263
- selector: 'page-home',
264
- templateUrl: 'home.html'
265
- })
266
- export class HomePage {
267
- items: Observable<any[]>;
268
-
269
- constructor(public navCtrl: NavController, afDB: AngularFireDatabase) {
270
- this.items = afDB.list('cuisines').valueChanges();
271
- }
272
-
273
- }
274
-
275
- ```
276
-
277
- *_Ensure you've `cuisines` node in your database with some primitive data._
278
-
279
- **Update** your `home.html` at `src/pages/home/home.html`, with following entry
280
-
281
- ```html
282
-
283
- <ion-header>
284
- <ion-navbar>
285
- <ion-title>
286
- Ionic Blank
287
- </ion-title>
288
- </ion-navbar>
289
- </ion-header>
290
-
291
- <ion-content padding>
292
- <ion-list>
293
- <ion-item class="text" *ngFor="let item of items | async">
294
- {{item | json}}
295
- </ion-item>
296
- </ion-list>
297
- </ion-content>
298
-
299
- ```
300
-
301
- **Run your app by executing the following command**
302
-
303
- ```bash
304
-
305
- C:\projects\auth-ng4-ionic3-af2> ionic serve
306
-
307
- ```
308
-
309
- This should fetch the data from firebase.
310
-
311
-
312
- ## Configuring Firebase/Facebook to talk to each other
313
-
314
- Go to Facebook Developers Page [here](https://developers.facebook.com/apps/) and create a new App.
315
-
316
- Once the App is created, get the `App ID` and `App Secret` from the dashboard and come back to _*Firebase Console*_.
317
-
318
- 1) Login to Firebase Console and click on the Authentication section on the left hand side of the menu.
319
- 2) Click on Sign-In Method tab and click on Facebook under Sign-In Providers.
320
- 3) Paste the `App ID` and `App Secret` copied from Facebook dashboard here.
321
- 4) Next copy the "OAuth redirect URI" from Firebase console. We need to go back and add it in Facebook dashboard.
322
-
323
- _This URI is important, since it tells facebook, where to redirect a user, once he is successfully authenticated._
324
-
325
- 5) Click the Save button and come back to the facebook dashboard.
326
-
327
- Go to your app in Facebook developers site ( Facebook Dashboard )
328
-
329
- 6) Ensure you see `Facebook Login` under products section, if not add it via the Add Product Button.
330
- 7) Once you see Facebook Login under products, click on the button to go to settings and there you should
331
- see "Valid OAuth redirect URIs" input field.
332
- 8) Enter the URI copied from Firebase Console and click on Save Changes.
333
-
334
- *_That's it. This will ensure Facebook and Firebase are able to talk to each other._*
335
-
336
- `As we were able to fetch data from Firebase database in the above step, let's focus on authentication below, by
337
- removing calls to fetch data.`
338
-
339
- *Let's add the following two buttons in our `home.html`*
340
-
341
- The `home.html` should look like below
342
-
343
- ```html
344
-
345
- <ion-header>
346
- <ion-navbar>
347
- <ion-title>
348
- Auth with Ionic
349
- </ion-title>
350
- </ion-navbar>
351
- </ion-header>
352
-
353
- <ion-content padding>
354
- <button ion-button outline (click)="signInWithFacebook()">Login</button>
355
- <button ion-button outline (click)="signOut()">Logout</button>
356
- </ion-content>
357
-
358
- ```
359
-
360
- Let's update the `home.ts` to add the corresponding methods:
361
-
362
- 1) First import AngularFireAuth from `angularfire2/auth`.
363
- 2) Inject AngularFireAuth in the constructor
364
- 3) The AngularFireAuth has various signIn methods to which we can pass instance of AuthProviders as shown below.
365
-
366
- The `home.ts` should look like below
367
-
368
- ```typescript
369
- import { Component } from '@angular/core';
370
- import { NavController } from 'ionic-angular';
371
-
372
- import { AngularFireAuth } from '@angular/fire/compat/auth';
373
- import firebase from 'firebase/app';
374
-
375
- @Component({
376
- selector: 'page-home',
377
- templateUrl: 'home.html'
378
- })
379
- export class HomePage {
380
-
381
- constructor(public navCtrl: NavController,
382
- private afAuth: AngularFireAuth) { }
383
-
384
- signInWithFacebook() {
385
- this.afAuth.auth
386
- .signInWithPopup(new firebase.auth.FacebookAuthProvider())
387
- .then(res => console.log(res));
388
- }
389
-
390
- signOut() {
391
- this.afAuth.auth.signOut();
392
- }
393
-
394
- }
395
-
396
- ```
397
- **_Note the import of firebase from firebase/app, to take advantage of the tree-shaking_**
398
-
399
- Also, update your `app.module.ts` to contain following import
400
-
401
- `import { AngularFireAuthModule } from '@angular/fire/compat/auth';`
402
-
403
- and add it to the imports array.
404
-
405
-
406
- Run the app and click on the Login Button, you should see a pop-up asking you to enter username and password for Facebook to
407
- authenticate. Once authenticated, you should see the response from Facebook in console window.
408
-
409
- Inspect the Object in the console, under `user` property, you should see all the attributes and we're going to use two of them, next.
410
-
411
- Let's get the `displayName` from the `user` property, which we just saw on the console to be rendered on the screen.
412
- The `AngularFireAuth` has an `authState` property, which returns an observable, let's subcribe it to get notified everytime the
413
- Authentication state changes.
414
-
415
- Add class property `displayName` and subscribe to the AngularFireAuth.authState property in the constructor.
416
- Also add the property in our template to render them on screen.
417
-
418
- Your `home.ts` should look as follows:
419
-
420
- ```typescript
421
-
422
- import { Component } from '@angular/core';
423
- import { NavController } from 'ionic-angular';
424
-
425
- import { AngularFireAuth } from '@angular/fire/compat/auth';
426
- import firebase from 'firebase/app';
427
-
428
- @Component({
429
- selector: 'page-home',
430
- templateUrl: 'home.html'
431
- })
432
- export class HomePage {
433
-
434
- displayName;
435
-
436
- constructor(public navCtrl: NavController,
437
- private afAuth: AngularFireAuth) {
438
- afAuth.authState.subscribe(user => {
439
- if (!user) {
440
- this.displayName = null;
441
- return;
442
- }
443
- this.displayName = user.displayName;
444
- });
445
- }
446
-
447
- signInWithFacebook() {
448
- this.afAuth.auth
449
- .signInWithPopup(new firebase.auth.FacebookAuthProvider())
450
- .then(res => console.log(res));
451
- }
452
-
453
- signOut() {
454
- this.afAuth.auth.signOut();
455
- }
456
-
457
- }
458
-
459
-
460
- ```
461
-
462
- and `home.html` should look like this:
463
-
464
- ```html
465
-
466
- <ion-header>
467
- <ion-navbar>
468
- <ion-title>
469
- Auth with Ionic
470
- </ion-title>
471
- </ion-navbar>
472
- </ion-header>
473
-
474
- <ion-content padding>
475
-
476
- <h1>Hello {{displayName}}</h1>
477
-
478
- <button ion-button outline (click)="signInWithFacebook()">Login</button>
479
- <button ion-button outline (click)="signOut()">Logout</button>
480
- </ion-content>
481
-
482
- ```
483
-
484
- Now run your app and if everything is configured correctly, you should be able to click on the login button in your app,
485
- which should open the facebook pop-up.
486
-
487
- Once you authenticate yourself, you should see your Facebook display name on your screen.
488
- Click the Logout button, which will make the AuthState to null and you should see the difference on your screen.
489
-
490
- You can try redirecting yourself to another page to grab additional details from Facebook and experiment on your own.
491
-
492
-
493
- ***Running our application on mobile phone***
494
-
495
- Ensure you've the platform added to your project. If not add the platform by executing the following command:
496
-
497
- ```
498
-
499
- C:\projects\auth-ng4-ionic3-af2>ionic platform add android
500
-
501
- ```
502
-
503
- This adds android platform for your project.
504
- Replace android with ios, if you're on Mac book or add both. The generic command is ```ionic platform add <platform-name>```
505
-
506
- Now, let's try to run the app in browser. Execute the command:
507
-
508
- ```
509
-
510
- C:\projects\auth-ng4-ionic3-af2> ionic run android
511
-
512
- ```
513
-
514
- This should run the app on your mobile phone. Now click on the Facebook button and you'll notice the button doesn't work anymore.
515
- This is because the code written so far is good for running our application in browsers, but when running the application on
516
- mobile phones, we need to have access to ***Native Mobile API's***, which are provided by _Cordova Plugins_.
517
-
518
- **We can access these cordova plugins, using Ionic Native, which are nothing but wrappers for cordova plugins.**
519
-
520
- List of all Ionic Native API's for cordova plugins can be found [here](http://ionicframework.com/docs/v2/native/).
521
-
522
- Let's look at configuring and installing the Facebook plugin [here](http://ionicframework.com/docs/v2/native/facebook/).
523
- _Ensure you follow the steps correctly to configure your app._
524
-
525
- Login to the Facebook dashboard [here](https://developers.facebook.com/apps/), go to your App and make a note of your App ID.
526
- Next go to command prompt in your project directory and execute the following command by replacing the `APP_ID` with your App Id
527
- and `APP_NAME` with your App Name.
528
-
529
- ```bash
530
-
531
- C:\projects\auth-ng4-ionic3-af2>
532
- ionic cordova plugin add cordova-plugin-facebook4 --variable APP_ID="123456789" --variable APP_NAME="myApplication"
533
-
534
- ```
535
-
536
- This should add the following entry in your config.xml, located at the root of your project:
537
-
538
- ```xml
539
-
540
- <plugin name="cordova-plugin-facebook4" spec="~1.7.4">
541
- <variable name="APP_ID" value="1689092456387654" />
542
- <variable name="APP_NAME" value="auth-ng4-ionic3-af2" />
543
- </plugin>
544
-
545
- ```
546
- This will install the cordova plugin for facebook.
547
-
548
- You should also see a sub-folder named `cordova-plugin-facebook4` under your `plugins` folder.
549
-
550
- Add the native dependencies by executing the following command:
551
-
552
- ```bash
553
-
554
- C:\projects\auth-ng4-ionic3-af2>npm install --save @ionic-native/facebook
555
-
556
- ```
557
-
558
- After executing the above command, ensure you have the following entry in your `package.json`:
559
-
560
- ```bash
561
-
562
- "@ionic-native/facebook": "^3.12.1",
563
-
564
- ```
565
- Now import the `Platform` and `Facebook` objects in your `home.ts` and inject the objects in constructor.
566
-
567
- ```typescript
568
-
569
- import { Platform } from 'ionic-angular';
570
- import { Facebook } from '@ionic-native/facebook';
571
-
572
- ```
573
-
574
- Update the "signInWithFacebook" method and use Platform Service to determine the platform and run the appropriate code.
575
-
576
- Your `home.ts` should look as below:
577
-
578
- ```typescript
579
-
580
- import { Component } from '@angular/core';
581
- import { NavController } from 'ionic-angular';
582
-
583
- import { AngularFireAuth } from '@angular/fire/compat/auth';
584
- import firebase from 'firebase/app';
585
-
586
- import { Platform } from 'ionic-angular';
587
- import { Facebook } from '@ionic-native/facebook';
588
-
589
- @Component({
590
- selector: 'page-home',
591
- templateUrl: 'home.html'
592
- })
593
- export class HomePage {
594
-
595
- displayName;
596
-
597
- constructor(public navCtrl: NavController,
598
- private afAuth: AngularFireAuth, private fb: Facebook, private platform: Platform) {
599
- afAuth.authState.subscribe((user: firebase.User) => {
600
- if (!user) {
601
- this.displayName = null;
602
- return;
603
- }
604
- this.displayName = user.displayName;
605
- });
606
- }
607
-
608
- signInWithFacebook() {
609
- if (this.platform.is('cordova')) {
610
- return this.fb.login(['email', 'public_profile']).then(res => {
611
- const facebookCredential = firebase.auth.FacebookAuthProvider.credential(res.authResponse.accessToken);
612
- return firebase.auth().signInWithCredential(facebookCredential);
613
- })
614
- }
615
- else {
616
- return this.afAuth.auth
617
- .signInWithPopup(new firebase.auth.FacebookAuthProvider())
618
- .then(res => console.log(res));
619
- }
620
- }
621
-
622
- signOut() {
623
- this.afAuth.auth.signOut();
624
- }
625
-
626
- }
627
-
628
-
629
- ```
630
-
631
- You'll also need to add the "Facebook" object in the provider section in app.module.ts.
632
-
633
- The final `app.module.ts` should look like below:
634
-
635
- ```typescript
636
-
637
- import { BrowserModule } from '@angular/platform-browser';
638
- import { ErrorHandler, NgModule } from '@angular/core';
639
- import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
640
- import { SplashScreen } from '@ionic-native/splash-screen';
641
- import { StatusBar } from '@ionic-native/status-bar';
642
-
643
- import { MyApp } from './app.component';
644
- import { HomePage } from '../pages/home/home';
645
-
646
- import { AngularFireModule } from '@angular/fire/compat';
647
- import { AngularFireDatabaseModule } from '@angular/fire/compat/database';
648
- import { AngularFireAuthModule } from '@angular/fire/compat/auth';
649
- import { Facebook } from '@ionic-native/facebook';
650
-
651
- export const firebaseConfig = {
652
- apiKey: "xxxxxxxxxx",
653
- authDomain: "your-domain-name.firebaseapp.com",
654
- databaseURL: "https://your-domain-name.firebaseio.com",
655
- storageBucket: "your-domain-name.appspot.com",
656
- messagingSenderId: '<your-messaging-sender-id>'
657
- };
658
-
659
- @NgModule({
660
- declarations: [
661
- MyApp,
662
- HomePage
663
- ],
664
- imports: [
665
- BrowserModule,
666
- IonicModule.forRoot(MyApp),
667
- AngularFireModule.initializeApp(firebaseConfig),
668
- AngularFireDatabaseModule,
669
- AngularFireAuthModule
670
- ],
671
- bootstrap: [IonicApp],
672
- entryComponents: [
673
- MyApp,
674
- HomePage
675
- ],
676
- providers: [
677
- StatusBar,
678
- SplashScreen,
679
- {provide: ErrorHandler, useClass: IonicErrorHandler},
680
- Facebook
681
- ]
682
- })
683
- export class AppModule {}
684
-
685
-
686
- ```
687
-
688
- Verfiy your app is running in browser by executing the following command:
689
-
690
- ```bash
691
-
692
- C:\projects\auth-ng4-ionic3-af2>ionic serve
693
-
694
- ```
695
-
696
- Everything should work. Now trying running the app on your android phone:
697
-
698
- ```bash
699
-
700
- C:\projects\auth-ng4-ionic3-af2> ionic cordova run android
701
-
702
- ```
703
-
704
- Once the App launches click on the Login button. You should get the Facebook pop-up window. Enter your credentials.
705
- On successful authentication, you should see your Facebook Display name and profile picture on your screen.