I need to save FCM tokens to Firebase Database to send notifications. Is there a better way to do it? Now I do it like this:
FirebaseDatabase.getInstance().reference.child("users/${user.uid}/tokens").push().setValue(token)
This way, each time when the token is pushed, it has new unique id and can have same token.
Could you please give me an advice? Or maybe I can do it with firebase functions which will remove duplicates.
I solved this problem by using another way for saving tokens, now token saves like a key of the record.
FirebaseDatabase.getInstance().reference.child("users/${user.uid}/tokens").child(token).setValue(true)
I would advise against saving that information in a database.
Take in consideration that:
The registration token may change when:
- The app deletes Instance ID
- The app is restored on a new device
- The user uninstalls/reinstall the app
- The user clears app data.
Source
FirebaseInstanceId may be considered PID (personal identification data), so treat it accordingly - remember the new GDPR regulations kicking in March 2018 if you do business in the EU
Instead, I would just use the token to register the user for push notifications where needed and send it to your FCM/GCM server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With