You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
build: require firebase ^12.18.0 and wrap the functions it adds (#3761)
The generated src/<module>/firebase.ts files are written from the type
declarations of the installed firebase, which decides which functions
AngularFire wraps. That was 12.4.0 while npm latest reached 12.18.0, leaving
everything firebase added in between to reach callers through `export *`, with
no zone integration and no pending-task registration.
Raising the required version wraps them. Everything the override entries in
#3759 classified as unwrapped stays out. `getImagenModel` loses its entry
because firebase removed the symbol in 12.18.0, and the exemption list it sat
in is empty now and stays as the place the next unclassified name goes.
Only `src/messaging/firebase.ts` changes among the generated files, gaining
onRegistered, onUnregistered, register and unregister. `docs/messaging.md` was
updated to use those calls. The Node send example keeps its token field, which
Firebase says still accepts an installation ID during the migration, rather
than the fid field it recommends, because firebase-admin 13.5.0 does not
declare one.
`exportsSeenPerOverrides` is keyed by the overrides object, and firestore and
firestore/lite are handed the same firestoreOverrides, so a name listed for one
silences the check for the other.
Fixes#3756
Copy file name to clipboardExpand all lines: docs/messaging.md
+77-48Lines changed: 77 additions & 48 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@
6
6
7
7
# Cloud Messaging
8
8
9
-
Firebase FCM allows you to register devices with unique FCM tokens, that you can later programtically send notifications to using Firebase Cloud Functions. It is up to the application to update these tokens in Firebase if you want to use them in other layers of your application, i.e send a notification to all administrators, etc. In that case, you would likely want to store your fcm tokens on your user collection, or a sub collection or another collection with different permissions.
9
+
Firebase Cloud Messaging (FCM) allows you to register devices with unique FCM tokens, that you can later programatically send notifications to using Firebase Cloud Functions. It is up to the application to update these tokens in Firebase if you want to use them in other layers of your application, i.e send a notification to all administrators, etc. In that case, you would likely want to store your fcm tokens on your user collection, or a sub collection or another collection with different permissions.
10
10
11
11
## Dependency Injection
12
12
@@ -47,19 +47,20 @@ export class AppComponent {
47
47
48
48
# Create a Firebase Messaging Service Worker
49
49
50
-
There are two parts to Firebase Messaging, a Service Worker and the DOM API. Angular Fire Messaging allows you to request permission, get tokens, delete tokens, and subscribe to messages on the DOM side. To register to receive notifications you need to set up the Service Worker. [The official Firebase documentation for setting up the details exactly how to do that](https://firebase.google.com/docs/cloud-messaging/js/client).
50
+
There are two parts to Firebase Messaging, a Service Worker and the DOM API. Angular Fire Messaging allows you to request permission, register this app instance, observe when it is registered or unregistered, and subscribe to messages on the DOM side. To register to receive notifications you need to set up the Service Worker. [The official Firebase documentation for setting up the details exactly how to do that](https://firebase.google.com/docs/cloud-messaging/js/client).
51
51
52
52
#### Create your firebase-messaging-sw.js file in your src/assets folder
53
53
54
54
*Note: When copying the below file, make sure your firebase version in your installation matches the version your are importing from below*
55
55
56
56
It may be wise to use file replacements or environments here for different environments
57
57
58
-
```
59
-
// This sample application is using 12.4.0, make sure you are importing the same version
58
+
```js
59
+
/* Replace <firebase-version> with the firebase version in your package.json. The service
60
+
* worker and your application have to load the same version. */
60
61
61
-
import { initializeApp } from "https://www.gstatic.com/firebasejs/12.4.0/firebase-app.js";
62
-
import { getMessaging } from "https://www.gstatic.com/firebasejs/12.4.0/firebase-messaging-sw.js";
Firebase deprecated `getToken` and `deleteToken` in firebase 12.18 and will remove them. Use `register` with `onRegistered` in place of `getToken`, and `unregister` with `onUnregistered` in place of `deleteToken`. [Firebase's client guide](https://firebase.google.com/docs/cloud-messaging/js/client) describes the model and asks that you not mix the two sets.
80
+
81
+
Three things to know before you copy the example below:
82
+
83
+
-`onRegistered` has to be listening before `register` runs, which is why the example subscribes first. Otherwise `register` throws `No onRegistered callback handler was provided or registered.`
84
+
-**Ask for notification permission yourself before calling `register`,** as the example does. Otherwise `register` asks for you from inside a call AngularFire wraps, which holds the client app unstable until the dialog is dismissed.
85
+
- That delays Angular event replay and clearing the server-rendered DOM, and logs a development-only warning after ten seconds. Asking first avoids all of it.
86
+
- This behavior may change in a future release.
87
+
- The identifier reaches you through a callback rather than as a return value, and again whenever it changes, so store it from inside the callback rather than once at startup.
88
+
76
89
# Example messaging service
77
90
78
-
```
79
-
import { Injectable } from "@angular/core";
80
-
import { Messaging, MessagePayload, getToken, onMessage, deleteToken } from "@angular/fire/messaging";
/* Run `register` inside an injection context. Outside one AngularFire cannot wrap it, and
139
+
* warns. See `zones.md` for what wrapping adds. */
140
+
runInInjectionContext(this.injector, () =>
141
+
register(this.msg, {
142
+
vapidKey: `an optional public VAPID key you generate for your Firebase project`,
143
+
serviceWorkerRegistration,
144
+
}).catch((error) =>console.error("could not register for messages", error))
117
145
);
118
146
}
119
147
120
-
async deleteToken() {
121
-
// We can also delete fcm tokens, make sure to also update this on your firestore db if you are storing them as well
122
-
// This calls the imported deleteToken, not this method. Class methods are not in lexical scope
123
-
await deleteToken(this.msg);
148
+
// Called from your app, for example when a user turns notifications off.
149
+
async unregister() {
150
+
// This calls the imported unregister, not this method. Class methods are not in lexical scope.
151
+
awaitunregister(this.msg);
124
152
}
125
153
}
126
154
```
@@ -129,9 +157,9 @@ export class FcmService {
129
157
130
158
Firebase will allow you to send a test notification under Engage > Messaging > New Campaign > Notifications. Here you can click send a test message. Additionally, you can send them programmatically through Firebase cloud functions.
131
159
132
-
Here is a barebones Node example:
160
+
Here is a barebones Node example. Its `token` field still accepts a Firebase Installation ID during the migration, so it works whether you registered with `getToken` or with `register`. Firebase's [Admin SDK send guide](https://firebase.google.com/docs/cloud-messaging/send/admin-sdk) documents a dedicated `fid` field to move to.
Here is a Node example that listens for a new comment on a collection, then sends a notification, and also adds it to a cache on Firebase so users can click through them.
Copy file name to clipboardExpand all lines: docs/version-21-upgrade.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ ng update @angular/fire # then AngularFire 21
11
11
12
12
`ng update @angular/fire` runs a migration that:
13
13
14
-
-**Aligns your `firebase` dependency to `^12.4.0`.** AngularFire 21 requires Firebase JS SDK 12. If your app still requested `firebase` 11, npm would install both 11 and 12 side by side, and the two copies reject each other's objects at runtime. The migration updates the dependency and reinstalls so you end up with a single copy. Verify with `npm ls firebase`.
14
+
-**Aligns your `firebase` dependency to `^12.18.0`.** AngularFire 21 requires Firebase JS SDK 12, at 12.18 or later. If your app requested an older `firebase`, whether that is 11 or an earlier 12, npm would install both that copy and the one AngularFire needs side by side, and the two copies reject each other's objects at runtime. The migration updates the dependency and reinstalls so you end up with a single copy. Verify with `npm ls firebase`.
15
15
-**Rewrites Vertex AI imports to AI Logic** (see below).
0 commit comments