@angular/fire 16.0.0-canary.596e208 → 16.0.0-canary.78407bc

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 (253) hide show
  1. package/README.md +200 -0
  2. package/analytics/analytics.module.d.ts +2 -2
  3. package/analytics/firebase.d.ts +4 -1
  4. package/analytics/screen-tracking.service.d.ts +3 -3
  5. package/app-check/app-check.module.d.ts +3 -3
  6. package/app-check/firebase.d.ts +2 -1
  7. package/auth/auth.module.d.ts +2 -2
  8. package/auth/firebase.d.ts +3 -1
  9. package/auth-guard/auth-guard.d.ts +2 -2
  10. package/compat/analytics/analytics.d.ts +1 -3
  11. package/compat/analytics/analytics.module.d.ts +1 -1
  12. package/compat/analytics/screen-tracking.service.d.ts +1 -1
  13. package/compat/analytics/user-tracking.service.d.ts +1 -1
  14. package/compat/auth/auth.d.ts +3 -3
  15. package/compat/auth-guard/auth-guard.d.ts +2 -2
  16. package/compat/database/database.d.ts +4 -4
  17. package/compat/database/interfaces.d.ts +2 -2
  18. package/compat/database/list/audit-trail.d.ts +1 -1
  19. package/compat/database/list/create-reference.d.ts +1 -1
  20. package/compat/database/list/data-operation.d.ts +1 -1
  21. package/compat/database/list/state-changes.d.ts +1 -1
  22. package/compat/database/object/create-reference.d.ts +1 -1
  23. package/compat/database/observable/fromRef.d.ts +1 -1
  24. package/compat/database/utils.d.ts +1 -1
  25. package/compat/firebase.app.module.d.ts +1 -1
  26. package/compat/firestore/collection/collection.d.ts +2 -2
  27. package/compat/firestore/collection-group/collection-group.d.ts +2 -2
  28. package/compat/firestore/document/document.d.ts +4 -4
  29. package/compat/firestore/firestore.d.ts +7 -7
  30. package/compat/firestore/interfaces.d.ts +2 -2
  31. package/compat/functions/functions.d.ts +3 -3
  32. package/compat/messaging/messaging.d.ts +2 -2
  33. package/compat/performance/performance.d.ts +2 -2
  34. package/compat/remote-config/remote-config.d.ts +15 -49
  35. package/compat/storage/observable/fromTask.d.ts +1 -2
  36. package/compat/storage/ref.d.ts +1 -1
  37. package/compat/storage/storage.d.ts +3 -3
  38. package/compat/storage/task.d.ts +1 -1
  39. package/database/database.module.d.ts +2 -2
  40. package/docs/analytics.md +67 -0
  41. package/docs/app-check.md +53 -0
  42. package/docs/auth.md +165 -0
  43. package/docs/compat/analytics/getting-started.md +137 -0
  44. package/docs/compat/auth/getting-started.md +162 -0
  45. package/docs/compat/auth/router-guards.md +104 -0
  46. package/docs/compat/emulators/emulators.md +134 -0
  47. package/docs/compat/firestore/collections.md +326 -0
  48. package/docs/compat/firestore/documents.md +115 -0
  49. package/docs/compat/firestore/offline-data.md +39 -0
  50. package/docs/compat/firestore/querying-collections.md +204 -0
  51. package/docs/compat/functions/functions.md +166 -0
  52. package/docs/compat/messaging/messaging.md +232 -0
  53. package/docs/compat/performance/getting-started.md +132 -0
  54. package/docs/compat/remote-config/getting-started.md +134 -0
  55. package/docs/compat/rtdb/lists.md +257 -0
  56. package/docs/compat/rtdb/objects.md +182 -0
  57. package/docs/compat/rtdb/querying-lists.md +155 -0
  58. package/docs/compat/storage/storage.md +257 -0
  59. package/docs/compat.md +70 -0
  60. package/docs/database.md +175 -0
  61. package/docs/deploy/getting-started.md +204 -0
  62. package/docs/firebase.json +16 -0
  63. package/docs/firestore.md +148 -0
  64. package/docs/functions.md +52 -0
  65. package/docs/images/analytics-illo_1x.png +0 -0
  66. package/docs/images/auth-illo_1x.png +0 -0
  67. package/docs/images/cloud-messaging-illo_1x.png +0 -0
  68. package/docs/images/database-illo_1x.png +0 -0
  69. package/docs/images/firestore-illo_1x.png +0 -0
  70. package/docs/images/functions-illo_1x.png +0 -0
  71. package/docs/images/hosting-illo_1x.png +0 -0
  72. package/docs/images/performance-illo_1x.png +0 -0
  73. package/docs/images/reCAPTCHA-logo@1x.png +0 -0
  74. package/docs/images/remote-config-illo_1x.png +0 -0
  75. package/docs/images/storage-illo_1x.png +0 -0
  76. package/docs/install-and-setup.md +114 -0
  77. package/docs/install-angular-cli-windows10.md +82 -0
  78. package/docs/install-firebase-tools.md +78 -0
  79. package/docs/messaging.md +25 -0
  80. package/docs/performance.md +57 -0
  81. package/docs/remote-config.md +53 -0
  82. package/docs/storage.md +90 -0
  83. package/docs/universal/cloud-functions.md +96 -0
  84. package/docs/universal/getting-started.md +28 -0
  85. package/docs/universal/prerendering.md +72 -0
  86. package/docs/version-4-upgrade.md +119 -0
  87. package/docs/version-5-upgrade.md +82 -0
  88. package/docs/version-6-upgrade.md +16 -0
  89. package/docs/version-7-upgrade.md +298 -0
  90. package/esm2022/analytics/analytics.mjs +1 -1
  91. package/esm2022/analytics/analytics.module.mjs +10 -10
  92. package/esm2022/analytics/firebase.mjs +5 -2
  93. package/esm2022/analytics/screen-tracking.service.mjs +11 -10
  94. package/esm2022/analytics/user-tracking.service.mjs +5 -5
  95. package/esm2022/app/app.mjs +1 -1
  96. package/esm2022/app/app.module.mjs +9 -8
  97. package/esm2022/app-check/app-check.mjs +2 -2
  98. package/esm2022/app-check/app-check.module.mjs +10 -11
  99. package/esm2022/app-check/firebase.mjs +3 -2
  100. package/esm2022/auth/auth.mjs +1 -1
  101. package/esm2022/auth/auth.module.mjs +10 -10
  102. package/esm2022/auth/firebase.mjs +4 -2
  103. package/esm2022/auth-guard/auth-guard.mjs +8 -6
  104. package/esm2022/auth-guard/auth-guard.module.mjs +7 -7
  105. package/esm2022/compat/analytics/analytics.mjs +12 -13
  106. package/esm2022/compat/analytics/analytics.module.mjs +14 -11
  107. package/esm2022/compat/analytics/screen-tracking.service.mjs +9 -9
  108. package/esm2022/compat/analytics/user-tracking.service.mjs +7 -7
  109. package/esm2022/compat/auth/auth.mjs +13 -13
  110. package/esm2022/compat/auth/auth.module.mjs +7 -7
  111. package/esm2022/compat/auth-guard/auth-guard.mjs +8 -6
  112. package/esm2022/compat/auth-guard/auth-guard.module.mjs +7 -7
  113. package/esm2022/compat/cache.mjs +2 -1
  114. package/esm2022/compat/database/database.mjs +10 -10
  115. package/esm2022/compat/database/database.module.mjs +7 -7
  116. package/esm2022/compat/database/interfaces.mjs +1 -1
  117. package/esm2022/compat/database/list/audit-trail.mjs +3 -3
  118. package/esm2022/compat/database/list/changes.mjs +5 -5
  119. package/esm2022/compat/database/list/create-reference.mjs +5 -5
  120. package/esm2022/compat/database/list/data-operation.mjs +1 -1
  121. package/esm2022/compat/database/list/snapshot-changes.mjs +1 -1
  122. package/esm2022/compat/database/list/state-changes.mjs +2 -2
  123. package/esm2022/compat/database/object/create-reference.mjs +2 -2
  124. package/esm2022/compat/database/object/snapshot-changes.mjs +1 -1
  125. package/esm2022/compat/database/observable/fromRef.mjs +3 -2
  126. package/esm2022/compat/database/utils.mjs +1 -1
  127. package/esm2022/compat/firebase.app.mjs +1 -1
  128. package/esm2022/compat/firebase.app.module.mjs +11 -9
  129. package/esm2022/compat/firestore/collection/changes.mjs +2 -2
  130. package/esm2022/compat/firestore/collection/collection.mjs +4 -4
  131. package/esm2022/compat/firestore/collection-group/collection-group.mjs +4 -4
  132. package/esm2022/compat/firestore/document/document.mjs +4 -4
  133. package/esm2022/compat/firestore/firestore.mjs +11 -11
  134. package/esm2022/compat/firestore/firestore.module.mjs +7 -7
  135. package/esm2022/compat/firestore/interfaces.mjs +1 -1
  136. package/esm2022/compat/firestore/observable/fromRef.mjs +2 -2
  137. package/esm2022/compat/functions/functions.mjs +8 -8
  138. package/esm2022/compat/functions/functions.module.mjs +7 -7
  139. package/esm2022/compat/messaging/messaging.mjs +13 -12
  140. package/esm2022/compat/messaging/messaging.module.mjs +7 -7
  141. package/esm2022/compat/performance/performance.mjs +14 -20
  142. package/esm2022/compat/performance/performance.module.mjs +8 -9
  143. package/esm2022/compat/performance/performance.service.mjs +5 -4
  144. package/esm2022/compat/proxy.mjs +6 -7
  145. package/esm2022/compat/remote-config/remote-config.mjs +10 -11
  146. package/esm2022/compat/remote-config/remote-config.module.mjs +7 -7
  147. package/esm2022/compat/storage/observable/fromTask.mjs +3 -1
  148. package/esm2022/compat/storage/pipes/storageUrl.pipe.mjs +9 -9
  149. package/esm2022/compat/storage/ref.mjs +3 -3
  150. package/esm2022/compat/storage/storage.mjs +8 -8
  151. package/esm2022/compat/storage/storage.module.mjs +7 -7
  152. package/esm2022/compat/storage/task.mjs +2 -2
  153. package/esm2022/core.mjs +1 -3
  154. package/esm2022/database/database.mjs +1 -1
  155. package/esm2022/database/database.module.mjs +10 -10
  156. package/esm2022/firestore/firebase.mjs +22 -2
  157. package/esm2022/firestore/firestore.mjs +1 -1
  158. package/esm2022/firestore/firestore.module.mjs +10 -10
  159. package/esm2022/firestore/lite/firebase.mjs +11 -2
  160. package/esm2022/firestore/lite/lite.mjs +1 -1
  161. package/esm2022/firestore/lite/lite.module.mjs +9 -9
  162. package/esm2022/firestore/lite/rxfire.mjs +4 -2
  163. package/esm2022/firestore/rxfire.mjs +4 -4
  164. package/esm2022/functions/functions.mjs +1 -1
  165. package/esm2022/functions/functions.module.mjs +10 -10
  166. package/esm2022/messaging/messaging.mjs +1 -1
  167. package/esm2022/messaging/messaging.module.mjs +9 -9
  168. package/esm2022/performance/performance.mjs +1 -1
  169. package/esm2022/performance/performance.module.mjs +12 -12
  170. package/esm2022/remote-config/is-remote-config-supported-factory.mjs +2 -2
  171. package/esm2022/remote-config/remote-config.mjs +1 -1
  172. package/esm2022/remote-config/remote-config.module.mjs +9 -9
  173. package/esm2022/storage/storage.mjs +1 -1
  174. package/esm2022/storage/storage.module.mjs +10 -10
  175. package/esm2022/zones.mjs +9 -11
  176. package/fesm2022/angular-fire-analytics.mjs +18 -14
  177. package/fesm2022/angular-fire-analytics.mjs.map +1 -1
  178. package/fesm2022/angular-fire-app-check.mjs +8 -8
  179. package/fesm2022/angular-fire-app-check.mjs.map +1 -1
  180. package/fesm2022/angular-fire-app.mjs +6 -5
  181. package/fesm2022/angular-fire-app.mjs.map +1 -1
  182. package/fesm2022/angular-fire-auth-guard.mjs +13 -11
  183. package/fesm2022/angular-fire-auth-guard.mjs.map +1 -1
  184. package/fesm2022/angular-fire-auth.mjs +8 -6
  185. package/fesm2022/angular-fire-auth.mjs.map +1 -1
  186. package/fesm2022/angular-fire-compat-analytics.mjs +29 -27
  187. package/fesm2022/angular-fire-compat-analytics.mjs.map +1 -1
  188. package/fesm2022/angular-fire-compat-auth-guard.mjs +12 -10
  189. package/fesm2022/angular-fire-compat-auth-guard.mjs.map +1 -1
  190. package/fesm2022/angular-fire-compat-auth.mjs +13 -13
  191. package/fesm2022/angular-fire-compat-auth.mjs.map +1 -1
  192. package/fesm2022/angular-fire-compat-database.mjs +129 -128
  193. package/fesm2022/angular-fire-compat-database.mjs.map +1 -1
  194. package/fesm2022/angular-fire-compat-firestore.mjs +96 -96
  195. package/fesm2022/angular-fire-compat-firestore.mjs.map +1 -1
  196. package/fesm2022/angular-fire-compat-functions.mjs +10 -10
  197. package/fesm2022/angular-fire-compat-functions.mjs.map +1 -1
  198. package/fesm2022/angular-fire-compat-messaging.mjs +13 -12
  199. package/fesm2022/angular-fire-compat-messaging.mjs.map +1 -1
  200. package/fesm2022/angular-fire-compat-performance.mjs +23 -29
  201. package/fesm2022/angular-fire-compat-performance.mjs.map +1 -1
  202. package/fesm2022/angular-fire-compat-remote-config.mjs +10 -11
  203. package/fesm2022/angular-fire-compat-remote-config.mjs.map +1 -1
  204. package/fesm2022/angular-fire-compat-storage.mjs +21 -19
  205. package/fesm2022/angular-fire-compat-storage.mjs.map +1 -1
  206. package/fesm2022/angular-fire-compat.mjs +15 -13
  207. package/fesm2022/angular-fire-compat.mjs.map +1 -1
  208. package/fesm2022/angular-fire-database.mjs +5 -5
  209. package/fesm2022/angular-fire-database.mjs.map +1 -1
  210. package/fesm2022/angular-fire-firestore-lite.mjs +19 -8
  211. package/fesm2022/angular-fire-firestore-lite.mjs.map +1 -1
  212. package/fesm2022/angular-fire-firestore.mjs +30 -10
  213. package/fesm2022/angular-fire-firestore.mjs.map +1 -1
  214. package/fesm2022/angular-fire-functions.mjs +6 -6
  215. package/fesm2022/angular-fire-functions.mjs.map +1 -1
  216. package/fesm2022/angular-fire-messaging.mjs +4 -4
  217. package/fesm2022/angular-fire-messaging.mjs.map +1 -1
  218. package/fesm2022/angular-fire-performance.mjs +7 -7
  219. package/fesm2022/angular-fire-performance.mjs.map +1 -1
  220. package/fesm2022/angular-fire-remote-config.mjs +4 -4
  221. package/fesm2022/angular-fire-remote-config.mjs.map +1 -1
  222. package/fesm2022/angular-fire-storage.mjs +4 -4
  223. package/fesm2022/angular-fire-storage.mjs.map +1 -1
  224. package/fesm2022/angular-fire.mjs +7 -11
  225. package/fesm2022/angular-fire.mjs.map +1 -1
  226. package/firestore/firebase.d.ts +21 -1
  227. package/firestore/firestore.module.d.ts +2 -2
  228. package/firestore/lite/firebase.d.ts +10 -1
  229. package/firestore/lite/lite.module.d.ts +2 -2
  230. package/firestore/lite/rxfire.d.ts +3 -1
  231. package/firestore/rxfire.d.ts +3 -3
  232. package/functions/functions.module.d.ts +2 -2
  233. package/messaging/messaging.module.d.ts +2 -2
  234. package/package.json +12 -12
  235. package/performance/performance.module.d.ts +2 -2
  236. package/remote-config/remote-config.module.d.ts +2 -2
  237. package/schematics/add/index.js +1 -1
  238. package/schematics/add/schema.json +16 -0
  239. package/schematics/builders.json +10 -0
  240. package/schematics/collection.json +15 -0
  241. package/schematics/common.js +1 -1
  242. package/schematics/deploy/actions.js +11 -11
  243. package/schematics/deploy/builder.js +2 -2
  244. package/schematics/deploy/schema.json +119 -0
  245. package/schematics/migration.json +15 -0
  246. package/schematics/setup/index.js +5 -6
  247. package/schematics/setup/prompts.js +5 -6
  248. package/schematics/setup/schema.json +16 -0
  249. package/schematics/update/index.js +1 -1
  250. package/schematics/update/v7/index.js +2 -2
  251. package/schematics/utils.js +4 -4
  252. package/storage/storage.module.d.ts +2 -2
  253. package/publish.sh +0 -1
@@ -0,0 +1,162 @@
1
+ # 5. Getting started with Firebase Authentication
2
+
3
+ `AngularFireAuth.user` provides you an `Observable<User|null>` to monitor your application's authentication State.
4
+
5
+ `AngularFireAuth` promise proxies an initialized
6
+ `firebase.auth.Auth` instance, allowing you to log users in, out, etc. [See
7
+ the Firebase docs for more information on what methods are available.](https://firebase.google.com/docs/reference/js/firebase.auth.Auth)
8
+
9
+ > **NOTE**: [AngularFire has a new tree-shakable API](../../../README.md#developer-guide), you're looking at the documentation for the compatability version of the library. [See the v7 upgrade guide for more information on this change.](../../version-7-upgrade.md).
10
+
11
+ **Example app:**
12
+
13
+ ```ts
14
+ import { Component } from '@angular/core';
15
+ import { AngularFireAuth } from '@angular/fire/compat/auth';
16
+ import firebase from 'firebase/compat/app';
17
+
18
+ @Component({
19
+ selector: 'app-root',
20
+ template: `
21
+ <div *ngIf="auth.user | async as user; else showLogin">
22
+ <h1>Hello {{ user.displayName }}!</h1>
23
+ <button (click)="logout()">Logout</button>
24
+ </div>
25
+ <ng-template #showLogin>
26
+ <p>Please login.</p>
27
+ <button (click)="login()">Login with Google</button>
28
+ </ng-template>
29
+ `,
30
+ })
31
+ export class AppComponent {
32
+ constructor(public auth: AngularFireAuth) {
33
+ }
34
+ login() {
35
+ this.auth.signInWithPopup(new firebase.auth.GoogleAuthProvider());
36
+ }
37
+ logout() {
38
+ this.auth.signOut();
39
+ }
40
+ }
41
+ ```
42
+
43
+ ## Configuration with Dependency Injection
44
+
45
+ The AngularFireAuth Module provides several DI tokens to further configure your
46
+ authentication process.
47
+
48
+ ### Configure
49
+
50
+ Using the `SETTINGS` DI Token (*default: null*), we can set the current Auth
51
+ instance's settings. This is used to edit/read configuration related options
52
+ like app verification mode for phone authentication, which is useful for
53
+ [testing](https://cloud.google.com/identity-platform/docs/test-phone-numbers).
54
+
55
+ ```ts
56
+ import { SETTINGS as AUTH_SETTINGS } from '@angular/fire/compat/auth';
57
+
58
+ @NgModule({
59
+ // ... Existing configuration
60
+ providers: [
61
+ // ... Existing Providers
62
+ { provide: AUTH_SETTINGS, useValue: { appVerificationDisabledForTesting: true } },
63
+ ]
64
+ })
65
+ export class AppModule { }
66
+ ```
67
+
68
+ Read more at [Firebase Auth Settings](https://firebase.google.com/docs/reference/js/firebase.auth.AuthSettings).
69
+
70
+ ### Use Current Browser Language
71
+
72
+ Using the `USE_DEVICE_LANGUAGE` DI Token (*default: null*), which is a boolean
73
+ that allow you to set the current language to the default device/browser
74
+ preference. This allows to localize emails but be aware that this only applies
75
+ if you use the standard template provided by Firebase.
76
+
77
+ ```ts
78
+ import { USE_DEVICE_LANGUAGE } from '@angular/fire/compat/auth';
79
+
80
+ @NgModule({
81
+ // ... Existing configuration
82
+ providers: [
83
+ // ... Existing Providers
84
+ { provide: USE_DEVICE_LANGUAGE, useValue: true },
85
+ ]
86
+ })
87
+ export class AppModule { }
88
+ ```
89
+
90
+ If you want to set a different language, you can use `LANGUAGE_CODE` DI Token
91
+ (*default: null*).
92
+
93
+ More info at the [firebase auth docs](https://firebase.google.com/docs/reference/js/firebase.auth.Auth#languagecode).
94
+
95
+ ```ts
96
+ import { LANGUAGE_CODE } from '@angular/fire/compat/auth';
97
+
98
+ @NgModule({
99
+ // ... Existing configuration
100
+ providers: [
101
+ // ... Existing Providers
102
+ { provide: LANGUAGE_CODE, useValue: 'fr' },
103
+ ]
104
+ })
105
+ export class AppModule { }
106
+ ```
107
+
108
+ ### Persistence
109
+
110
+ Firebase Auth default behavior is to persist a user's session even after the
111
+ user closes the browser. To change the current type of persistence on the
112
+ current Auth instance for the currently saved Auth session and apply this type
113
+ of persistence for future sign-in requests, including sign-in with redirect
114
+ requests, you can use the `PERSISTENCE` DI Token (*default: null*).
115
+
116
+ The possible types are `'local'`, `'session'` or `'none'`. Read more at
117
+ [authentication state persistence](https://firebase.google.com/docs/auth/web/auth-state-persistence).
118
+
119
+ ```ts
120
+ import { PERSISTENCE } from '@angular/fire/compat/auth';
121
+
122
+ @NgModule({
123
+ // ... Existing configuration
124
+ providers: [
125
+ // ... Existing Providers
126
+ { provide: PERSISTENCE, useValue: 'session' },
127
+ ]
128
+ })
129
+ export class AppModule { }
130
+ ```
131
+
132
+ ### Tenant
133
+
134
+ If you need to use multi-tenancy, you can set the current Auth instance's tenant
135
+ ID using `TENANT_ID` DI Token (*default: null*).
136
+
137
+ More tutorials regarding this topic are _coming soon_.
138
+
139
+ ```ts
140
+ import { TENANT_ID } from '@angular/fire/compat/auth';
141
+
142
+ @NgModule({
143
+ // ... Existing configuration
144
+ providers: [
145
+ // ... Existing Providers
146
+ { provide: TENANT_ID, useValue: 'tenant-id-app-one' },
147
+ ]
148
+ })
149
+ export class AppModule { }
150
+ ```
151
+
152
+ - [Multi-Tenancy Authentication](https://cloud.google.com/identity-platform/docs/multi-tenancy-authentication)
153
+ - [Firebase Auth Tenant](https://firebase.google.com/docs/reference/js/firebase.auth.Auth#tenantid)
154
+
155
+ ## UI Libraries
156
+
157
+ - Material Design : [ngx-auth-firebaseui](https://github.com/AnthonyNahas/ngx-auth-firebaseui)
158
+ - Bootstrap : [@firebaseui/ng-bootstrap](https://github.com/firebaseui/ng-bootstrap)
159
+
160
+ ## Cordova
161
+
162
+ Learn how to [setup Firebase Authentication with Cordova](https://firebase.google.com/docs/auth/web/cordova) in the Firebase Guides.
@@ -0,0 +1,104 @@
1
+ # Route users with AngularFire guards
2
+
3
+ `AngularFireAuthGuard` provides a prebuilt [`canActivate` Router Guard](https://angular.io/api/router/CanActivate) using `AngularFireAuth`. By default unauthenticated users are not permitted to navigate to protected routes:
4
+
5
+ > **NOTE**: [AngularFire has a new tree-shakable API](../../../README.md#developer-guide), you're looking at the documentation for the compatability version of the library. [See the v7 upgrade guide for more information on this change.](../../version-7-upgrade.md).
6
+
7
+ ```ts
8
+ import { AngularFireAuthGuard } from '@angular/fire/compat/auth-guard';
9
+
10
+ export const routes: Routes = [
11
+ { path: '', component: AppComponent },
12
+ { path: 'items', component: ItemListComponent, canActivate: [AngularFireAuthGuard] },
13
+ ]
14
+ ```
15
+
16
+ ## Customizing the behavior of `AngularFireAuthGuard`
17
+
18
+ To customize the behavior of `AngularFireAuthGuard`, you can pass an RXJS pipe through the route data's `authGuardPipe` key.
19
+
20
+ The `auth-guard` module provides the following pre-built pipes:
21
+
22
+ | Exported pipe | Functionality |
23
+ |-|-|
24
+ | `loggedIn` | The default pipe, rejects if the user is not authenticated. |
25
+ | `isNotAnonymous` | Rejects if the user is anonymous |
26
+ | `emailVerified` | Rejects if the user's email is not verified |
27
+ | `hasCustomClaim(claim)` | Rejects if the user does not have the specified claim |
28
+ | `redirectUnauthorizedTo(redirect)` | Redirect unauthenticated users to a different route |
29
+ | `redirectLoggedInTo(redirect)` | Redirect authenticated users to a different route |
30
+
31
+ Example use:
32
+
33
+ ```ts
34
+ import { AngularFireAuthGuard, hasCustomClaim, redirectUnauthorizedTo, redirectLoggedInTo } from '@angular/fire/compat/auth-guard';
35
+
36
+ const adminOnly = () => hasCustomClaim('admin');
37
+ const redirectUnauthorizedToLogin = () => redirectUnauthorizedTo(['login']);
38
+ const redirectLoggedInToItems = () => redirectLoggedInTo(['items']);
39
+ const belongsToAccount = (next) => hasCustomClaim(`account-${next.params.id}`);
40
+
41
+ export const routes: Routes = [
42
+ { path: '', component: AppComponent },
43
+ { path: 'login', component: LoginComponent, canActivate: [AngularFireAuthGuard], data: { authGuardPipe: redirectLoggedInToItems }},
44
+ { path: 'items', component: ItemListComponent, canActivate: [AngularFireAuthGuard], data: { authGuardPipe: redirectUnauthorizedToLogin }},
45
+ { path: 'admin', component: AdminComponent, canActivate: [AngularFireAuthGuard], data: { authGuardPipe: adminOnly }},
46
+ { path: 'accounts/:id', component: AdminComponent, canActivate: [AngularFireAuthGuard], data: { authGuardPipe: belongsToAccount }}
47
+ ];
48
+ ```
49
+
50
+ Use the provided `canActivate` helper and spread syntax to make your routes more readable:
51
+
52
+ ```ts
53
+ import { canActivate } from '@angular/fire/compat/auth-guard';
54
+
55
+ export const routes: Routes = [
56
+ { path: '', component: AppComponent },
57
+ { path: 'login', component: LoginComponent, ...canActivate(redirectLoggedInToItems) },
58
+ { path: 'items', component: ItemListComponent, ...canActivate(redirectUnauthorizedToLogin) },
59
+ { path: 'admin', component: AdminComponent, ...canActivate(adminOnly) },
60
+ { path: 'accounts/:id', component: AdminComponent, ...canActivate(belongsToAccount) }
61
+ ];
62
+ ```
63
+
64
+ ### Compose your own pipes
65
+
66
+ `AngularFireAuthGuard` pipes are RXJS operators which transform an optional User to a boolean or Array (for redirects). You can easily build your own to customize behavior further:
67
+
68
+ ```ts
69
+ import { map } from 'rxjs/operators';
70
+
71
+ // This pipe redirects a user to their "profile edit" page or the "login page" if they're unauthenticated
72
+ // { path: 'profile', ...canActivate(redirectToProfileEditOrLogin) }
73
+ const redirectToProfileEditOrLogin = () => map(user => user ? ['profiles', user.uid, 'edit'] : ['login']);
74
+ ```
75
+
76
+ The `auth-guard` modules provides a `customClaims` operator to reduce boiler plate when checking a user's claims:
77
+
78
+ ```ts
79
+ import { pipe } from 'rxjs';
80
+ import { map } from 'rxjs/operators';
81
+ import { customClaims } from '@angular/fire/compat/auth-guard';
82
+
83
+ // This pipe will only allow users with the editor role to access the route
84
+ // { path: 'articles/:id/edit', component: ArticleEditComponent, ...canActivate(editorOnly) }
85
+ const editorOnly = () => pipe(customClaims, map(claims => claims.role === 'editor'));
86
+ ```
87
+
88
+ ### Using router state
89
+
90
+ `AngularFireAuthGuard` will also accept `AuthPipeGenerator`s which generate `AuthPipe`s given the router state:
91
+
92
+ ```ts
93
+ import { pipe } from 'rxjs';
94
+ import { map } from 'rxjs/operators';
95
+ import { customClaims } from '@angular/fire/compat/auth-guard';
96
+
97
+ // Only allow navigation to the route if :userId matches the authenticated user's uid
98
+ // { path: 'user/:userId/edit', component: ProfileEditComponent, ...canActivate(onlyAllowSelf) }
99
+ const onlyAllowSelf = (next) => map(user => !!user && next.params.userId === user.uid);
100
+
101
+ // Only allow navigation to the route if the user has a custom claim matching :accountId
102
+ // { path: 'accounts/:accountId/billing', component: BillingDetailsComponent, ...canActivate(accountAdmin) }
103
+ const accountAdmin = (next) => pipe(customClaims, map(claims => claims[`account-${next.params.accountId}-role`] === 'admin'));
104
+ ```
@@ -0,0 +1,134 @@
1
+ # Connect your app and start prototyping
2
+
3
+ In this guide, we'll look at how to use `@angular/fire` to connect an Angular application with Firebase Emulator Suite to start prototyping your apps.
4
+
5
+ > **NOTE**: [AngularFire has a new tree-shakable API](../../../README.md#developer-guide), you're looking at the documentation for the compatability version of the library. [See the v7 upgrade guide for more information on this change.](../../version-7-upgrade.md).
6
+
7
+ There are four supported emulators, all of them available at the Firebase suite workflow:
8
+
9
+ - [Authentication Emulator](https://firebase.google.com/docs/emulator-suite/connect_auth)
10
+ - [Realtime Database Emulator](https://firebase.google.com/docs/emulator-suite/connect_rtdb)
11
+ - [Cloud Firestore Emulator](https://firebase.google.com/docs/emulator-suite/connect_firestore)
12
+ - [Cloud Functions Emulator](https://firebase.google.com/docs/emulator-suite/connect_functions)
13
+
14
+ **The Auth Emulator only works with Firebase v8 and above, which is supported by `@angular/fire` 6.1.0 or higher**.
15
+
16
+ Before configuring these emulators at the Angular App, be sure to install the ones you need by following the [Install, configure and integrate Local Emulator Suite](https://firebase.google.com/docs/emulator-suite/install_and_configure) documentation.
17
+
18
+ _**TL;DR**_
19
+
20
+ Initialize firebase to your project (if you haven't) by running:
21
+
22
+ ```shell
23
+ firebase init
24
+ ```
25
+
26
+ Then launch the emulator setup wizard by running:
27
+
28
+ ```shell
29
+ firebase init emulators
30
+ ```
31
+
32
+ Follow the instructions to download whatever emulator you want to use then checkout that the `firebase.json` file got updated with the default ports per emulator, something like this:
33
+
34
+ ```jsonc
35
+ {
36
+ // Existing firebase configuration ...
37
+ // Optional emulator configuration. Default
38
+ // values are used if absent.
39
+ "emulators": {
40
+ "firestore": {
41
+ "port": "8080"
42
+ },
43
+ "ui": {
44
+ "enabled": true, // Default is `true`
45
+ "port": 4000 // If unspecified, see CLI log for selected port
46
+ },
47
+ "auth": {
48
+ "port": "9099"
49
+ },
50
+ "functions": {
51
+ "port": "5001"
52
+ },
53
+ "database": {
54
+ "port": "9000"
55
+ },
56
+ "pubsub": {
57
+ "port": "8085"
58
+ }
59
+ }
60
+ }
61
+ ```
62
+
63
+ ## Import the DI Tokens at your AppModule
64
+
65
+ Configuring your app to connect to local emulators is easily done by using dependency injection tokens provided by the library. However, there are slighty changes between 6.0.0 and 6.1.0 in the way it was done.
66
+
67
+ ### 6.1.0 Method
68
+
69
+ Each module (database, firestore, auth, function) provides `USE_EMULATOR` token to configure the emulator `host` and `port` by passing a tuple of `[string, number]` values, which are set by default to `localhost` and the asigned port from your `firebase.json` file.
70
+
71
+ Import these tokens at your `app.module.ts` as follow:
72
+
73
+ ```ts
74
+ import { USE_EMULATOR as USE_AUTH_EMULATOR } from '@angular/fire/compat/auth';
75
+ import { USE_EMULATOR as USE_DATABASE_EMULATOR } from '@angular/fire/compat/database';
76
+ import { USE_EMULATOR as USE_FIRESTORE_EMULATOR } from '@angular/fire/compat/firestore';
77
+ import { USE_EMULATOR as USE_FUNCTIONS_EMULATOR } from '@angular/fire/compat/functions';
78
+
79
+ @NgModule({
80
+ // ... Existing configuration
81
+ providers: [
82
+ // ... Existing Providers
83
+ { provide: USE_AUTH_EMULATOR, useValue: environment.useEmulators ? ['localhost', 9099] : undefined },
84
+ { provide: USE_DATABASE_EMULATOR, useValue: environment.useEmulators ? ['localhost', 9000] : undefined },
85
+ { provide: USE_FIRESTORE_EMULATOR, useValue: environment.useEmulators ? ['localhost', 8080] : undefined },
86
+ { provide: USE_FUNCTIONS_EMULATOR, useValue: environment.useEmulators ? ['localhost', 5001] : undefined },
87
+ ]
88
+ })
89
+ export class AppModule { }
90
+ ```
91
+
92
+ The environment `useEmulators` flag is used to control whenever the app should connect to the emulators, which is usually done in non-production environments.
93
+
94
+ Also you can opt-in the new way of setting the Cloud Functions [origin](https://firebase.google.com/docs/functions/locations) in Firebase v8 by using the `NEW_ORIGIN_BEHAVIOR` token in conjuction with the already present `ORIGIN` token.
95
+
96
+ ```ts
97
+ import { isDevMode, NgModule } from '@angular/core';
98
+ import { ORIGIN as FUNCTIONS_ORIGIN, NEW_ORIGIN_BEHAVIOR } from '@angular/fire/compat/functions';
99
+
100
+ @NgModule({
101
+ // ... Existing configuration
102
+ providers: [
103
+ // ... Existing Providers
104
+ { provide: NEW_ORIGIN_BEHAVIOR, useValue: true },
105
+ { provide: FUNCTIONS_ORIGIN, useFactory: () => isDevMode() ? undefined : location.origin },
106
+ ]
107
+ })
108
+ export class AppModule { }
109
+ ```
110
+
111
+ ### 6.0.0 Method
112
+
113
+ With the exception of the Auth Emulator, the old way of setting the `host` and `port` for each emulator was done using a different set of tokens by passing the entire url path as string.
114
+
115
+ ```ts
116
+ import { URL as DATABASE_URL } from '@angular/fire/compat/database';
117
+ import { ORIGIN as FUNCTIONS_ORIGIN } from '@angular/fire/compat/functions';
118
+ import { SETTINGS as FIRESTORE_SETTINGS } from '@angular/fire/compat/firestore';
119
+
120
+ @NgModule({
121
+ // ... Existing configuration
122
+ providers: [
123
+ {
124
+ provide: DATABASE_URL,
125
+ useValue: environment.useEmulators ? `http://localhost:9000?ns=${environment.firebase.projectId}` : undefined
126
+ },
127
+ { provide: FIRESTORE_SETTINGS, useValue: environment.useEmulators ? { host: 'localhost:8080', ssl: false } : {} },
128
+ { provide: FUNCTIONS_ORIGIN, useFactory: environment.useEmulators ? 'http://localhost:5001' : undefined },
129
+ ]
130
+ })
131
+ export class AppModule { }
132
+ ```
133
+
134
+ For older versions, please upgrade your app to latest version to get the advantages of these new features :rocket: