@angular/fire 20.0.3 → 21.0.0-canary.20260927231611.sha-ac17ede

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 (146) hide show
  1. package/README.md +41 -32
  2. package/ai/package.json +2 -1
  3. package/analytics/package.json +2 -1
  4. package/app/package.json +2 -1
  5. package/app-check/package.json +2 -1
  6. package/auth/package.json +2 -1
  7. package/auth-guard/package.json +2 -1
  8. package/compat/analytics/package.json +2 -1
  9. package/compat/auth/package.json +2 -1
  10. package/compat/auth-guard/package.json +2 -1
  11. package/compat/database/package.json +2 -1
  12. package/compat/firestore/package.json +2 -1
  13. package/compat/functions/package.json +2 -1
  14. package/compat/messaging/package.json +2 -1
  15. package/compat/package.json +2 -1
  16. package/compat/performance/package.json +2 -1
  17. package/compat/remote-config/package.json +2 -1
  18. package/compat/storage/package.json +2 -1
  19. package/data-connect/package.json +2 -1
  20. package/database/package.json +2 -1
  21. package/docs/ai.md +52 -0
  22. package/docs/analytics.md +2 -5
  23. package/docs/app-check.md +6 -8
  24. package/docs/app-hosting.md +95 -0
  25. package/docs/auth.md +214 -29
  26. package/docs/compat/auth/router-guards.md +1 -1
  27. package/docs/compat.md +1 -1
  28. package/docs/data-connect.md +56 -0
  29. package/docs/database.md +14 -12
  30. package/docs/deploy/getting-started.md +2 -0
  31. package/docs/firestore.md +7 -7
  32. package/docs/functions.md +3 -5
  33. package/docs/install-and-setup.md +43 -24
  34. package/docs/install-firebase-tools.md +2 -0
  35. package/docs/messaging.md +83 -52
  36. package/docs/performance.md +3 -5
  37. package/docs/remote-config.md +3 -5
  38. package/docs/storage.md +3 -5
  39. package/docs/version-21-upgrade.md +90 -0
  40. package/docs/zones.md +45 -1
  41. package/fesm2022/angular-fire-ai.mjs +8 -8
  42. package/fesm2022/angular-fire-ai.mjs.map +1 -1
  43. package/fesm2022/angular-fire-analytics.mjs +10 -10
  44. package/fesm2022/angular-fire-analytics.mjs.map +1 -1
  45. package/fesm2022/angular-fire-app-check.mjs +4 -4
  46. package/fesm2022/angular-fire-app-check.mjs.map +1 -1
  47. package/fesm2022/angular-fire-app.mjs +5 -6
  48. package/fesm2022/angular-fire-app.mjs.map +1 -1
  49. package/fesm2022/angular-fire-auth-guard.mjs +7 -7
  50. package/fesm2022/angular-fire-auth-guard.mjs.map +1 -1
  51. package/fesm2022/angular-fire-auth.mjs +4 -4
  52. package/fesm2022/angular-fire-auth.mjs.map +1 -1
  53. package/fesm2022/angular-fire-compat-analytics.mjs +17 -21
  54. package/fesm2022/angular-fire-compat-analytics.mjs.map +1 -1
  55. package/fesm2022/angular-fire-compat-auth-guard.mjs +7 -7
  56. package/fesm2022/angular-fire-compat-auth-guard.mjs.map +1 -1
  57. package/fesm2022/angular-fire-compat-auth.mjs +9 -11
  58. package/fesm2022/angular-fire-compat-auth.mjs.map +1 -1
  59. package/fesm2022/angular-fire-compat-database.mjs +11 -13
  60. package/fesm2022/angular-fire-compat-database.mjs.map +1 -1
  61. package/fesm2022/angular-fire-compat-firestore.mjs +12 -14
  62. package/fesm2022/angular-fire-compat-firestore.mjs.map +1 -1
  63. package/fesm2022/angular-fire-compat-functions.mjs +7 -7
  64. package/fesm2022/angular-fire-compat-functions.mjs.map +1 -1
  65. package/fesm2022/angular-fire-compat-messaging.mjs +9 -11
  66. package/fesm2022/angular-fire-compat-messaging.mjs.map +1 -1
  67. package/fesm2022/angular-fire-compat-performance.mjs +13 -17
  68. package/fesm2022/angular-fire-compat-performance.mjs.map +1 -1
  69. package/fesm2022/angular-fire-compat-remote-config.mjs +11 -16
  70. package/fesm2022/angular-fire-compat-remote-config.mjs.map +1 -1
  71. package/fesm2022/angular-fire-compat-storage.mjs +16 -18
  72. package/fesm2022/angular-fire-compat-storage.mjs.map +1 -1
  73. package/fesm2022/angular-fire-compat.mjs +8 -9
  74. package/fesm2022/angular-fire-compat.mjs.map +1 -1
  75. package/fesm2022/angular-fire-data-connect.mjs +4 -4
  76. package/fesm2022/angular-fire-data-connect.mjs.map +1 -1
  77. package/fesm2022/angular-fire-database.mjs +4 -4
  78. package/fesm2022/angular-fire-database.mjs.map +1 -1
  79. package/fesm2022/angular-fire-firestore-lite.mjs +4 -4
  80. package/fesm2022/angular-fire-firestore-lite.mjs.map +1 -1
  81. package/fesm2022/angular-fire-firestore.mjs +9 -6
  82. package/fesm2022/angular-fire-firestore.mjs.map +1 -1
  83. package/fesm2022/angular-fire-functions.mjs +4 -4
  84. package/fesm2022/angular-fire-functions.mjs.map +1 -1
  85. package/fesm2022/angular-fire-messaging.mjs +10 -6
  86. package/fesm2022/angular-fire-messaging.mjs.map +1 -1
  87. package/fesm2022/angular-fire-performance.mjs +5 -8
  88. package/fesm2022/angular-fire-performance.mjs.map +1 -1
  89. package/fesm2022/angular-fire-remote-config.mjs +7 -6
  90. package/fesm2022/angular-fire-remote-config.mjs.map +1 -1
  91. package/fesm2022/angular-fire-storage.mjs +4 -4
  92. package/fesm2022/angular-fire-storage.mjs.map +1 -1
  93. package/fesm2022/angular-fire.mjs +4 -6
  94. package/fesm2022/angular-fire.mjs.map +1 -1
  95. package/firestore/lite/package.json +2 -1
  96. package/firestore/package.json +2 -1
  97. package/functions/package.json +2 -1
  98. package/messaging/package.json +2 -1
  99. package/package.json +73 -69
  100. package/performance/package.json +2 -1
  101. package/publish.sh +1 -1
  102. package/remote-config/package.json +2 -1
  103. package/schematics/add/index.js +1 -1
  104. package/schematics/deploy/actions.js +76 -85
  105. package/schematics/deploy/builder.js +161 -170
  106. package/schematics/deploy/schema.json +6 -3
  107. package/schematics/migration.json +4 -4
  108. package/schematics/setup/index.js +162 -142
  109. package/schematics/update/v21/index.js +1 -0
  110. package/schematics/update/v7/index.js +1 -1
  111. package/storage/package.json +2 -1
  112. package/{ai/index.d.ts → types/angular-fire-ai.d.ts} +4 -4
  113. package/{app/index.d.ts → types/angular-fire-app.d.ts} +1 -1
  114. package/{auth-guard/index.d.ts → types/angular-fire-auth-guard.d.ts} +2 -2
  115. package/{compat/analytics/index.d.ts → types/angular-fire-compat-analytics.d.ts} +2 -2
  116. package/{compat/auth-guard/index.d.ts → types/angular-fire-compat-auth-guard.d.ts} +2 -2
  117. package/{compat/auth/index.d.ts → types/angular-fire-compat-auth.d.ts} +1 -1
  118. package/{compat/database/index.d.ts → types/angular-fire-compat-database.d.ts} +5 -6
  119. package/{compat/firestore/index.d.ts → types/angular-fire-compat-firestore.d.ts} +5 -11
  120. package/{compat/functions/index.d.ts → types/angular-fire-compat-functions.d.ts} +1 -1
  121. package/{compat/messaging/index.d.ts → types/angular-fire-compat-messaging.d.ts} +2 -2
  122. package/{compat/performance/index.d.ts → types/angular-fire-compat-performance.d.ts} +2 -2
  123. package/{compat/remote-config/index.d.ts → types/angular-fire-compat-remote-config.d.ts} +3 -3
  124. package/{compat/storage/index.d.ts → types/angular-fire-compat-storage.d.ts} +18 -18
  125. package/{compat/index.d.ts → types/angular-fire-compat.d.ts} +2 -2
  126. package/{firestore/lite/index.d.ts → types/angular-fire-firestore-lite.d.ts} +1 -1
  127. package/{firestore/index.d.ts → types/angular-fire-firestore.d.ts} +6 -3
  128. package/{messaging/index.d.ts → types/angular-fire-messaging.d.ts} +6 -2
  129. package/{remote-config/index.d.ts → types/angular-fire-remote-config.d.ts} +3 -2
  130. package/docs/firebase.json +0 -16
  131. package/docs/install-angular-cli-windows10.md +0 -82
  132. package/docs/vertexai.md +0 -53
  133. package/fesm2022/angular-fire-vertexai.mjs +0 -102
  134. package/fesm2022/angular-fire-vertexai.mjs.map +0 -1
  135. package/schematics/update/index.js +0 -1
  136. package/vertexai/index.d.ts +0 -33
  137. package/vertexai/package.json +0 -3
  138. /package/{analytics/index.d.ts → types/angular-fire-analytics.d.ts} +0 -0
  139. /package/{app-check/index.d.ts → types/angular-fire-app-check.d.ts} +0 -0
  140. /package/{auth/index.d.ts → types/angular-fire-auth.d.ts} +0 -0
  141. /package/{data-connect/index.d.ts → types/angular-fire-data-connect.d.ts} +0 -0
  142. /package/{database/index.d.ts → types/angular-fire-database.d.ts} +0 -0
  143. /package/{functions/index.d.ts → types/angular-fire-functions.d.ts} +0 -0
  144. /package/{performance/index.d.ts → types/angular-fire-performance.d.ts} +0 -0
  145. /package/{storage/index.d.ts → types/angular-fire-storage.d.ts} +0 -0
  146. /package/{index.d.ts → types/angular-fire.d.ts} +0 -0
package/docs/auth.md CHANGED
@@ -15,14 +15,12 @@ Firebase Authentication integrates tightly with other Firebase services, and it
15
15
 
16
16
  ## Dependency Injection
17
17
 
18
- As a prerequisite, ensure that `AngularFire` has been added to your project via
19
- ```bash
20
- ng add @angular/fire
21
- ```
18
+ As a prerequisite, ensure that `AngularFire` has been added to your project as described in the [Quickstart](./install-and-setup.md).
22
19
 
23
- Provide a Auth instance in the application's `app.config.ts`:
20
+ Provide an Auth instance in the application's `app.config.ts`:
24
21
 
25
22
  ```ts
23
+ import { ApplicationConfig } from '@angular/core';
26
24
  import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
27
25
  import { provideAuth, getAuth } from '@angular/fire/auth';
28
26
 
@@ -33,7 +31,7 @@ export const appConfig: ApplicationConfig = {
33
31
  ...
34
32
  ],
35
33
  ...
36
- })
34
+ }
37
35
  ```
38
36
 
39
37
  Next inject `Auth` into your component:
@@ -59,13 +57,159 @@ Update the imports from `import { ... } from 'firebase/auth'` to `import { ... }
59
57
 
60
58
  ## Server-side Rendering
61
59
 
62
- To support Auth context in server-side rendering, you can provide `FirebaseServerApp`:
60
+ When Angular renders your app on the server, the server does not know which user is visiting. To render the page as that user, pass their Auth ID token to `initializeServerApp`, which gives you a Firebase app that is already signed in as them.
61
+
62
+ Getting the token to the server is your app's job. This guide keeps it in a cookie, because the browser attaches cookies to every request on its own.
63
+
64
+ All 4 steps below are required. Miss any one of them and the page still renders, but it renders signed out, with no error to tell you why.
65
+
66
+ ### 1. Serve the route with `RenderMode.Server`
67
+
68
+ `ng new --ssr` scaffolds `app.routes.server.ts` with every route set to `RenderMode.Prerender`. Prerendering runs at build time, so there is no request and no cookie, and Angular provides neither `REQUEST` nor `REQUEST_CONTEXT`. Any route that must already render as the signed-in user before hydration has to be `RenderMode.Server`. A `RenderMode.Client` route renders in the browser, where the user is already signed in, so it needs none of this.
69
+
70
+ ```ts
71
+ import { RenderMode, ServerRoute } from '@angular/ssr';
72
+
73
+ export const serverRoutes: ServerRoute[] = [
74
+ { path: 'account', renderMode: RenderMode.Server },
75
+ { path: '**', renderMode: RenderMode.Prerender },
76
+ ];
77
+ ```
78
+
79
+ The rest of this guide has no effect on routes rendered any other way.
80
+
81
+ ### 2. Keep the ID token in a cookie
82
+
83
+ Install [js-cookie](https://github.com/js-cookie/js-cookie):
84
+
85
+ ```bash
86
+ npm install js-cookie
87
+ npm install --save-dev @types/js-cookie
88
+ ```
89
+
90
+ Add the cookie sync to your `app.config.ts`. AngularFire's `idToken` observable emits on sign-in, on sign-out, and whenever the token is refreshed.
63
91
 
64
92
  ```ts
65
- import { ApplicationConfig, PLATFORM_ID, inject } from '@angular/core';
93
+ import { DestroyRef, PLATFORM_ID, inject, provideAppInitializer } from '@angular/core';
66
94
  import { isPlatformBrowser } from '@angular/common';
67
- import { provideFirebaseApp, initializeApp, initializeServeApp, initializeServerApp } from '@angular/fire/app';
68
- import { provideAuth, getAuth } from '@angular/fire/auth';
95
+ import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
96
+ import { Auth, idToken } from '@angular/fire/auth';
97
+ import { beforeAuthStateChanged } from 'firebase/auth';
98
+ import cookies from 'js-cookie';
99
+
100
+ // add to appConfig.providers
101
+ provideAppInitializer(() => {
102
+ if (!isPlatformBrowser(inject(PLATFORM_ID))) {
103
+ return;
104
+ }
105
+ const auth = inject(Auth);
106
+ const destroyRef = inject(DestroyRef);
107
+
108
+ const writeSessionCookie = (token: string | undefined) => {
109
+ if (token) {
110
+ cookies.set('__session', token, { secure: true, sameSite: 'lax' });
111
+ } else {
112
+ cookies.remove('__session');
113
+ }
114
+ };
115
+
116
+ idToken(auth)
117
+ .pipe(takeUntilDestroyed(destroyRef))
118
+ .subscribe((token) => writeSessionCookie(token ?? undefined));
119
+
120
+ let priorToken: string | undefined;
121
+ const unsubscribe = beforeAuthStateChanged(
122
+ auth,
123
+ async (user) => {
124
+ // Must update the cookie before the sign-out completes, otherwise a page
125
+ // load that races it still sends the signed-out user's token.
126
+ priorToken = cookies.get('__session');
127
+ writeSessionCookie(await user?.getIdToken());
128
+ },
129
+ () => writeSessionCookie(priorToken)
130
+ );
131
+ destroyRef.onDestroy(unsubscribe);
132
+ }),
133
+ ```
134
+
135
+ The 2 hooks cover different moments:
136
+ - `idToken` fires after an auth state change has completed, and also when Firebase refreshes the token in the background, which is what keeps the cookie current.
137
+ - `beforeAuthStateChanged` fires earlier, while an auth state change is still in progress and before Firebase sets the new user, so a page load that races a sign-out cannot send a token for the user who just left and get their data rendered back. Its third argument puts the cookie back if another blocking callback rejects the auth state change.
138
+
139
+ Name the cookie `__session`. Behind Firebase Hosting it is the [only cookie forwarded](https://firebase.google.com/docs/hosting/manage-cache#using_cookies) to your server code, and any other name is dropped before your app sees it.
140
+
141
+ #### Both attributes matter
142
+
143
+ The cookie sync above sets `{ secure: true, sameSite: 'lax' }`, and neither attribute is optional.
144
+
145
+ - `secure` keeps the cookie off unencrypted connections. Browsers make an exception for `localhost`, so local development still works.
146
+ - `sameSite: 'lax'` keeps the cookie off cross-site requests while still sending it when someone follows a link into your app, which is what lets that first page render signed in. If your app never needs a signed-in first render from an external link, use `'strict'` instead.
147
+
148
+ #### What this cookie carries
149
+
150
+ This cookie carries a short-lived ID token that scripts on your page can read. Firebase already keeps the signed-in state in browser storage, so the cookie does not create a new place for a token to be stolen from, but it does travel on every request.
151
+
152
+ If you need a session the browser cannot read, use Firebase's [session cookies](https://firebase.google.com/docs/auth/admin/manage-cookies) with the Admin SDK instead. Those cannot be handed to `initializeServerApp`, so that approach means verifying the cookie yourself and building your own server-side Auth context.
153
+
154
+ #### `beforeAuthStateChanged` from `firebase/auth`
155
+
156
+ One import in the code above is deliberately different from the rest of this guide. `beforeAuthStateChanged` comes from `firebase/auth` rather than `@angular/fire/auth`. AngularFire's version keeps the app marked as busy until its callback first runs, and this callback only runs when someone signs in or out.
157
+
158
+ Importing it from `@angular/fire/auth` makes `ng build` hang during route extraction and fail with a timeout. That is a bug on our side, tracked in [#3748](https://github.com/angular/angularfire/issues/3748). Once the fix lands, this can be imported from `@angular/fire/auth` like everything else.
159
+
160
+ ### 3. Pass the cookie into the render
161
+
162
+ Install [cookie-parser](https://github.com/expressjs/cookie-parser):
163
+
164
+ ```bash
165
+ npm install cookie-parser
166
+ npm install --save-dev @types/cookie-parser
167
+ ```
168
+
169
+ The `server.ts` the Angular CLI generated already renders your app for every request that is not a static file. Replace that existing `app.use` block with this one, which reads the cookie and hands the token to the render. Do not add a second block, because the first one to match wins and the token would never arrive:
170
+
171
+ ```ts
172
+ // server.ts
173
+ import cookieParser from 'cookie-parser';
174
+
175
+ app.use(cookieParser());
176
+
177
+ app.use((req, res, next) => {
178
+ angularApp
179
+ .handle(req, { authIdToken: req.cookies?.__session })
180
+ .then((response) =>
181
+ response ? writeResponseToNodeResponse(response, res) : next(),
182
+ )
183
+ .catch(next);
184
+ });
185
+ ```
186
+
187
+ Keep it where the generated block already was, below the block that serves static files, so real files are still served before Angular tries to render them. The rest of the file, including the part that starts the server, stays as it is.
188
+
189
+ The second argument to `handle` is what the render reads back as `REQUEST_CONTEXT`.
190
+
191
+ ### 4. Build the server app from the token
192
+
193
+ In `app.config.ts`, choose the Firebase app based on where the code is running, and pass that app to every Firebase provider:
194
+
195
+ ```ts
196
+ import {
197
+ ApplicationConfig,
198
+ PLATFORM_ID,
199
+ REQUEST_CONTEXT,
200
+ inject,
201
+ } from '@angular/core';
202
+ import { isPlatformBrowser } from '@angular/common';
203
+ import {
204
+ FirebaseApp,
205
+ initializeApp,
206
+ initializeServerApp,
207
+ provideFirebaseApp,
208
+ } from '@angular/fire/app';
209
+ import { getAuth, provideAuth } from '@angular/fire/auth';
210
+ import { getFirestore, provideFirestore } from '@angular/fire/firestore';
211
+
212
+ const firebaseConfig = { /* ...your Firebase configuration... */ };
69
213
 
70
214
  export const appConfig: ApplicationConfig = {
71
215
  providers: [
@@ -73,22 +217,60 @@ export const appConfig: ApplicationConfig = {
73
217
  if (isPlatformBrowser(inject(PLATFORM_ID))) {
74
218
  return initializeApp(firebaseConfig);
75
219
  }
76
- // Optional, since it's null in dev-mode and SSG
77
- const request = inject(REQUEST, { optional: true });
78
- const authIdToken = request?.headers.authorization?.split("Bearer ")[1];
220
+ const requestContext = inject(REQUEST_CONTEXT, { optional: true }) as
221
+ | { authIdToken?: string }
222
+ | null;
223
+ if (!requestContext?.authIdToken) {
224
+ return initializeApp(firebaseConfig);
225
+ }
79
226
  return initializeServerApp(firebaseConfig, {
80
- authIdToken,
81
- releaseOnDeref: request || undefined
227
+ authIdToken: requestContext.authIdToken,
228
+ releaseOnDeref: requestContext,
82
229
  });
83
230
  }),
84
- provideAuth(() => getAuth(inject(FirebaseApp)),
85
- ...
231
+ provideAuth(() => getAuth(inject(FirebaseApp))),
232
+ provideFirestore(() => getFirestore(inject(FirebaseApp))),
233
+ // ...
86
234
  ],
87
- ...
88
- })
235
+ };
89
236
  ```
90
237
 
91
- Follow Firebase's [ Session Management with Service Workers documentation](https://firebase.google.com/docs/auth/web/service-worker-sessions) to learn how to pass the `idToken` to the server. __Note: this will not currently work in dev-mode as Angular SSR does not provide a method to get the Request headers.__
238
+ #### Five details make this work
239
+
240
+ - **Keep exactly one `provideFirebaseApp`.** AngularFire hands you the app you provided only when a single one is registered, and falls back to the default app otherwise. A second registration anywhere in your configuration would make the server app be silently ignored.
241
+ - **Pass `inject(FirebaseApp)` to every provider, not just `provideAuth`.** `ng add @angular/fire` writes them without an argument, which resolves the default app. On a signed-in request the factory above builds a server app instead, so a provider that asks for the default app fails outright on a freshly started server.
242
+ - **Keep the signed-out fallback.** There is no request context when Angular prerenders a page, and no token when the visitor is signed out, so the fallback builds an ordinary Firebase app and the page renders signed out.
243
+ - **Pass `releaseOnDeref`.** It tells the SDK when it may release the server app. The SDK watches the object you give it and releases once that object is garbage collected, so pass one that lives exactly as long as the render, such as the request context itself. Leave it out and the SDK requires you to call `deleteApp` yourself for each server app you create.
244
+ - **The cast is needed** because Angular types `REQUEST_CONTEXT` as `unknown`.
245
+
246
+ AngularFire's [sample app](https://github.com/angular/angularfire/tree/main/sample) does this differently, giving the browser and the server their own `app.config.client.ts` and `app.config.server.ts` instead of deciding at runtime, inside a single `provideFirebaseApp` factory, which of `initializeApp` and `initializeServerApp` to call. That is also fine, and it keeps the server-only code out of the browser bundle, at the cost of an extra file to wire up.
247
+
248
+ ID tokens are short-lived, and a returning visitor's browser can send one that expired while the tab was closed. The server cannot refresh it, because a user restored from an ID token has no refresh token, so Firebase logs an error and the page renders signed out. The browser then refreshes the token and the page updates.
249
+
250
+ ### Using `REQUEST` instead of a cookie
251
+
252
+ Angular also exposes the request itself through the `REQUEST` token, so you can read the ID token from an `Authorization` header rather than a cookie. Firebase's [session management with service workers](https://firebase.google.com/docs/auth/web/service-worker-sessions) guide covers attaching that header. Steps 1, 3 and 4 stay the same apart from the server half of the factory, which becomes:
253
+
254
+ ```ts
255
+ import { PLATFORM_ID, REQUEST, inject } from '@angular/core';
256
+
257
+ provideFirebaseApp(() => {
258
+ if (isPlatformBrowser(inject(PLATFORM_ID))) {
259
+ return initializeApp(firebaseConfig);
260
+ }
261
+ const request = inject(REQUEST, { optional: true });
262
+ const authIdToken = request?.headers.get('authorization')?.split('Bearer ')[1];
263
+ if (!authIdToken) {
264
+ return initializeApp(firebaseConfig);
265
+ }
266
+ return initializeServerApp(firebaseConfig, {
267
+ authIdToken,
268
+ releaseOnDeref: request,
269
+ });
270
+ }),
271
+ ```
272
+
273
+ `REQUEST` is a standard [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request), so headers are read with `headers.get(...)`. Angular sets it to `null` during builds, during static site generation, and during route extraction in development, and it is only supplied at all on `RenderMode.Server` routes, so keep the signed-out fallback for those passes.
92
274
 
93
275
  ## Convenience observables
94
276
 
@@ -106,7 +288,7 @@ import { Auth, User, user } from '@angular/fire/auth';
106
288
 
107
289
  export class UserComponent implements OnDestroy {
108
290
  private auth: Auth = inject(Auth);
109
- user$ = user(auth);
291
+ user$ = user(this.auth);
110
292
  userSubscription: Subscription;
111
293
  ...
112
294
 
@@ -136,7 +318,7 @@ import { Auth, authState } from '@angular/fire/auth';
136
318
 
137
319
  export class UserComponent implements OnDestroy {
138
320
  private auth: Auth = inject(Auth);
139
- authState$ = authState(auth);
321
+ authState$ = authState(this.auth);
140
322
  authStateSubscription: Subscription;
141
323
  ...
142
324
 
@@ -165,14 +347,14 @@ import { Auth, idToken } from '@angular/fire/auth';
165
347
 
166
348
  export class UserComponent implements OnDestroy {
167
349
  private auth: Auth = inject(Auth);
168
- idToken$ = idToken(auth);
350
+ idToken$ = idToken(this.auth);
169
351
  idTokenSubscription: Subscription;
170
352
  ...
171
353
 
172
354
  constructor() {
173
355
  this.idTokenSubscription = this.idToken$.subscribe((token: string | null) => {
174
- //handle idToken changes here. Note, that user will be null if there is no currently logged in user.
175
- console.log(string);
356
+ //handle idToken changes here. Note, that token will be null if there is no currently logged in user.
357
+ console.log(token);
176
358
  })
177
359
  }
178
360
 
@@ -186,15 +368,18 @@ export class UserComponent implements OnDestroy {
186
368
  ## Connecting the emulator suite
187
369
 
188
370
  ```ts
371
+ import { ApplicationConfig, inject } from '@angular/core';
372
+ import { FirebaseApp, provideFirebaseApp, initializeApp } from '@angular/fire/app';
189
373
  import { connectAuthEmulator, getAuth, provideAuth } from '@angular/fire/auth';
190
374
 
191
- @NgModule({
192
- imports: [
375
+ export const appConfig: ApplicationConfig = {
376
+ providers: [
377
+ provideFirebaseApp(() => initializeApp({ ... })),
193
378
  provideAuth(() => {
194
- const auth = getAuth();
379
+ const auth = getAuth(inject(FirebaseApp));
195
380
  connectAuthEmulator(auth, 'http://localhost:9099', { disableWarnings: true });
196
381
  return auth;
197
382
  }),
198
383
  ]
199
- })
384
+ }
200
385
  ```
@@ -1,6 +1,6 @@
1
1
  # Route users with AngularFire guards
2
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:
3
+ `AngularFireAuthGuard` provides a prebuilt [`canActivate` Router Guard](https://angular.dev/api/router/CanActivate) using `AngularFireAuth`. By default unauthenticated users are not permitted to navigate to protected routes:
4
4
 
5
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
6
 
package/docs/compat.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # AngularFire
2
- The official [Angular](https://angular.io/) library for [Firebase](https://firebase.google.com/).
2
+ The official [Angular](https://angular.dev/) library for [Firebase](https://firebase.google.com/).
3
3
 
4
4
  <strong><pre>ng add @angular/fire</pre></strong>
5
5
 
@@ -0,0 +1,56 @@
1
+ <small>
2
+ <a href="https://github.com/angular/angularfire">AngularFire</a> &#10097; <a href="../README.md#developer-guide">Developer Guide</a> &#10097; Data Connect
3
+ </small>
4
+
5
+ # Data Connect
6
+
7
+ Firebase Data Connect (now known as "Firebase SQL Connect" in the Firebase documentation) is a backend service that pairs a Cloud SQL for PostgreSQL database with GraphQL, generating type-safe SDKs to query and mutate your data.
8
+
9
+ [Learn more](https://firebase.google.com/docs/data-connect)
10
+
11
+ ## Dependency Injection
12
+
13
+ As a prerequisite, ensure that `AngularFire` has been added to your project as described in the [Quickstart](./install-and-setup.md).
14
+
15
+ Provide a Data Connect instance in the application's `app.config.ts`. `getDataConnect` takes a connector config that identifies your service, connector, and location; this is generated for you when you set up Data Connect and is also exported from your generated SDK:
16
+
17
+ ```ts
18
+ import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
19
+ import { provideDataConnect, getDataConnect } from '@angular/fire/data-connect';
20
+
21
+ const connectorConfig = {
22
+ connector: 'my-connector',
23
+ service: 'my-service',
24
+ location: 'us-central1',
25
+ };
26
+
27
+ export const appConfig: ApplicationConfig = {
28
+ providers: [
29
+ provideFirebaseApp(() => initializeApp({ ... })),
30
+ provideDataConnect(() => getDataConnect(connectorConfig)),
31
+ ...
32
+ ],
33
+ ...,
34
+ }
35
+ ```
36
+
37
+ Next inject `DataConnect` into your component:
38
+
39
+ ```typescript
40
+ import { Component, inject } from '@angular/core';
41
+ import { DataConnect } from '@angular/fire/data-connect';
42
+
43
+ @Component({ ... })
44
+ export class MyComponent {
45
+ private dataConnect = inject(DataConnect);
46
+ ...
47
+ }
48
+ ```
49
+
50
+ ## Firebase API
51
+
52
+ AngularFire wraps the Firebase JS SDK to ensure proper functionality in Angular, while providing the same API.
53
+
54
+ Update the imports from `import { ... } from 'firebase/data-connect'` to `import { ... } from '@angular/fire/data-connect'` and follow the official documentation.
55
+
56
+ [Getting Started](https://firebase.google.com/docs/data-connect/quickstart)
package/docs/database.md CHANGED
@@ -12,14 +12,12 @@ The Firebase Realtime Database is a cloud-hosted database. Data is stored as JSO
12
12
 
13
13
  ## Dependency Injection
14
14
 
15
- As a prerequisite, ensure that `AngularFire` has been added to your project via
16
- ```bash
17
- ng add @angular/fire
18
- ```
15
+ As a prerequisite, ensure that `AngularFire` has been added to your project as described in the [Quickstart](./install-and-setup.md).
19
16
 
20
17
  Provide a Database instance in the application's `app.config.ts`:
21
18
 
22
19
  ```ts
20
+ import { ApplicationConfig } from '@angular/core';
23
21
  import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
24
22
  import { provideDatabase, getDatabase } from '@angular/fire/database';
25
23
 
@@ -30,7 +28,7 @@ export const appConfig: ApplicationConfig = {
30
28
  ...
31
29
  ],
32
30
  ...
33
- })
31
+ }
34
32
  ```
35
33
 
36
34
  Next inject `Database` into your component:
@@ -131,22 +129,26 @@ The `fromRef()` function creates an observable that emits reference changes.
131
129
  ## Connecting to the emulator suite
132
130
 
133
131
  ```ts
132
+ import { ApplicationConfig } from '@angular/core';
133
+ import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
134
134
  import { connectDatabaseEmulator, getDatabase, provideDatabase } from '@angular/fire/database';
135
135
 
136
- @NgModule({
137
- imports: [
136
+ export const appConfig: ApplicationConfig = {
137
+ providers: [
138
+ provideFirebaseApp(() => initializeApp({ ... })),
138
139
  provideDatabase(() => {
139
140
  const database = getDatabase();
140
141
  connectDatabaseEmulator(database, 'localhost', 9000);
141
142
  return database;
142
143
  }),
143
144
  ]
144
- })
145
+ }
145
146
  ```
146
147
 
147
148
  ## Working with multiple instances
148
149
 
149
150
  ```ts
151
+ import { ApplicationConfig } from '@angular/core';
150
152
  import { provideFirebaseApp, FirebaseApp, initializeApp } from '@angular/fire/app';
151
153
  import { getDatabase, provideDatabase } from '@angular/fire/database';
152
154
 
@@ -156,14 +158,14 @@ const DATABASE_SHARD_URLS = [
156
158
  'https://BAZ.firebaseio.com',
157
159
  ];
158
160
 
159
- @NgModule({
160
- imports: [
161
- provideFirebaseApp(() => initializeApp(environment.firebase)),
161
+ export const appConfig: ApplicationConfig = {
162
+ providers: [
163
+ provideFirebaseApp(() => initializeApp({ ... })),
162
164
  provideDatabase((app: FirebaseApp) => getDatabase(app, DATABASE_SHARD_URLS[0])),
163
165
  provideDatabase((app: FirebaseApp) => getDatabase(app, DATABASE_SHARD_URLS[1])),
164
166
  provideDatabase((app: FirebaseApp) => getDatabase(app, DATABASE_SHARD_URLS[2])),
165
167
  ]
166
- })
168
+ }
167
169
  ```
168
170
 
169
171
  ```ts
@@ -1,5 +1,7 @@
1
1
  # Deploy your application on Firebase Hosting & Functions
2
2
 
3
+ > **This page is out of date.** It describes a setup flow that `ng add @angular/fire` no longer performs, and wiring the deploy target by hand from the samples below puts you on a deprecated path that warns on every deploy. For current guidance see [the Quickstart](../install-and-setup.md), step 6, and for server-side rendered apps see the [App Hosting guide](../app-hosting.md).
4
+
3
5
  In this guide, we'll look at how to use `@angular/fire` to automatically deploy an Angular application to Firebase hosting or functions by using the Angular CLI.
4
6
 
5
7
  `@angular/fire` uses Firebase functions to deploy your Angular universal projects, with server-side rendering enabled.
package/docs/firestore.md CHANGED
@@ -14,13 +14,11 @@ Cloud Firestore is the API that gives your application access to your database i
14
14
 
15
15
  ## Dependency Injection
16
16
 
17
- As a prerequisite, ensure that `AngularFire` has been added to your project via
18
- ```bash
19
- ng add @angular/fire
20
- ```
17
+ As a prerequisite, ensure that `AngularFire` has been added to your project as described in the [Quickstart](./install-and-setup.md).
21
18
  Provide a Firestore instance in the application's `app.config.ts`:
22
19
 
23
20
  ```ts
21
+ import { ApplicationConfig } from '@angular/core';
24
22
  import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
25
23
  import { provideFirestore, getFirestore } from '@angular/fire/firestore';
26
24
 
@@ -71,6 +69,7 @@ In `user-profile.component.ts`:
71
69
  ```typescript
72
70
  import { Firestore, collection, collectionData} from '@angular/fire/firestore';
73
71
  import { Component, inject } from '@angular/core';
72
+ import { Observable } from 'rxjs';
74
73
 
75
74
  @Component ({
76
75
  selector: 'app-user-profile',
@@ -89,7 +88,7 @@ export class UserProfileComponent {
89
88
  this.users$ = collectionData(userProfileCollection) as Observable<UserProfile[]>;
90
89
  }
91
90
  }
92
- export Interface UserProfile {
91
+ export interface UserProfile {
93
92
  username: string;
94
93
  }
95
94
  ```
@@ -114,8 +113,9 @@ To write to Cloud Firestore use the `addDoc` function. It will create a new docu
114
113
 
115
114
 
116
115
  ```typescript
117
- import { Firestore, collection, collectionData, addDoc} from '@angular/fire/firestore';
116
+ import { Firestore, collection, collectionData, addDoc, CollectionReference, DocumentReference } from '@angular/fire/firestore';
118
117
  import { Component, inject } from '@angular/core';
118
+ import { Observable } from 'rxjs';
119
119
 
120
120
  @Component ({
121
121
  selector: 'app-user-profile',
@@ -137,7 +137,7 @@ export class UserProfileComponent {
137
137
  });
138
138
  }
139
139
  }
140
- export Interface UserProfile {
140
+ export interface UserProfile {
141
141
  username: string;
142
142
  }
143
143
  ```
package/docs/functions.md CHANGED
@@ -12,14 +12,12 @@ The Cloud Functions for Firebase client SDKs let you call functions directly fro
12
12
 
13
13
  ## Dependency Injection
14
14
 
15
- As a prerequisite, ensure that `AngularFire` has been added to your project via
16
- ```bash
17
- ng add @angular/fire
18
- ```
15
+ As a prerequisite, ensure that `AngularFire` has been added to your project as described in the [Quickstart](./install-and-setup.md).
19
16
 
20
17
  Provide a Cloud Functions instance in the application's `app.config.ts`:
21
18
 
22
19
  ```ts
20
+ import { ApplicationConfig } from '@angular/core';
23
21
  import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
24
22
  import { provideFunctions, getFunctions } from '@angular/fire/functions';
25
23
 
@@ -30,7 +28,7 @@ export const appConfig: ApplicationConfig = {
30
28
  ...
31
29
  ],
32
30
  ...
33
- })
31
+ }
34
32
  ```
35
33
 
36
34
  Next inject `Functions` into your component: