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
docs(messaging): add token management info to server integration doc (#5427)
Added additional section about handling tokens while logging out users, and about tokens being associated with the app installation instance. As discussed in the discussions #5423
Co-authored-by: Mike Hardy <[email protected]>
Copy file name to clipboardExpand all lines: docs/messaging/server-integration.md
+20-7Lines changed: 20 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ Firebase provides a number of SDKs in different languages such as [Node.JS](http
17
17
[HTTP](https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages). These methods allow you to send messages
18
18
directly to your user's devices via the FCM servers.
19
19
20
-
# Device tokens
20
+
##Device tokens
21
21
22
22
To send a message to a device, you must access its unique token. A token is automatically generated by the device and
23
23
can be accessed using the Cloud Messaging module. The token should be saved inside of your systems data-store and should
@@ -163,7 +163,20 @@ function App() {
163
163
Your application code can then handle messages as you see fit; updating local cache, displaying a [notification](/messaging/notifications)
164
164
or updating UI. The possibilities are endless!
165
165
166
-
# Send messages to topics
166
+
## Signing out users
167
+
168
+
Firebase Cloud Messaging tokens are associated with the instance of the installed app. By default, only token expiration or uninstalling/reinstalling the app will generate a fresh token.
169
+
170
+
This means that by default, if your app has users and you allow them to log out and log in on the same app on the same device, the same FCM token will be used for both users. Usually this is not what you want, so you must take care to cycle the FCM token at the same time you handle user logout/login.
171
+
172
+
How and when you invalidate a token and generate a new one will be specific to your project, but a common pattern is to delete the FCM token during logout and update your back end to remove ti, then to fetch the FCM token during login and update your back end systems to associate the new token with the logged in user.
Note that when a token is deleted by calling the `deleteToken` method, it is immediately and permanently invalid.
178
+
179
+
## Send messages to topics
167
180
168
181
When devices [subscribe to topics](/messaging/usage#topics), you can send messages without specifying/storing any device
169
182
tokens.
@@ -198,8 +211,8 @@ To send a message to a combination of topics, specify a condition, which is a bo
198
211
topics. For example, the following condition will send messages to devices that are subscribed to `weather` and either `news`
199
212
or `traffic`:
200
213
201
-
```
202
-
'weather' in topics && ('news' in topics || 'traffic' in topics)
214
+
```json
215
+
condition: "'weather' in topics && ('news' in topics || 'traffic' in topics)"
203
216
```
204
217
205
218
To send a message to this condition, replace the `topic` key with `condition`:
@@ -225,11 +238,11 @@ admin
225
238
});
226
239
```
227
240
228
-
# Send messages with image
241
+
##Send messages with image
229
242
230
243
Both the Notifications composer and the FCM API support image links in the message payload.
231
244
232
-
## iOS
245
+
###iOS
233
246
234
247
To successfully send an image using the Admin SDK it's important that the `ApnsConfig` options are set:
235
248
@@ -254,7 +267,7 @@ const payload = {
254
267
255
268
> Check out the [official Firebase documentation](https://firebase.google.com/docs/cloud-messaging/ios/send-image) to see the list of available configuration for iOS.
256
269
257
-
## Android
270
+
###Android
258
271
259
272
Similarly to iOS, some configurations specific to Android are needed:
0 commit comments