0

I don't want to have login or signup for my app. I've implemented fire-base notification in the app as well.

Can I use Fire-base FCM ID (token) as a unique user identifier. Instead of creating a user in the system I'll create a FCM table(id(pk), FCMID) and store all information of the user against that FCM id.

If yes then at what instance it changes the FCM id.

Cœur
  • 37,241
  • 25
  • 195
  • 267
safina
  • 212
  • 2
  • 13

2 Answers2

1

You can but you shouldn't

FCM token can change if you see the Service used for getting the FCM token, the one that has to extend FirebaseInsanceIdService the method inside is called onTokenRefresh() because it will be triggered every time the FCM token is refreshed for a new one. In previous Google Cloud Messaging (GCM) this strike to me as erratic, but in current FCM it seems to be infrequent.

You could do this by saving the current token in some form of local persistence (sharedpreference, database, etc). Then when the FCM is refreshed using the stored FCM the nodes in the real-time database can be updated.

This will have some bad scenarios: what happens if the user re-login by reinstalling or changing device? The first can be solved by saving something unique in the device, I have seen that some sort of devices ids can be get, but those are reset after boot or factory reset. Then a more general solution would make the user to input something unique to them every time they log in. It could be the email, or it could be the phone number.

Which leads me to, use phone authentication instead

cutiko
  • 9,887
  • 3
  • 45
  • 59
  • thank you for your detail reply. Yes i agree I should go for email or phone authentication otherwise it would be risky to retain user info considering many other possibilities. – safina Oct 20 '17 at 14:19
  • @stack you are welcome, just trying to help, Let me know if I can add anything else to get the correct answer :) – cutiko Oct 20 '17 at 14:25
  • 1
    Agreeing on this answer as it expresses the idea of *not* using the FCM tokens for user identification. Go with Firebase Auth, then use the auto-generated uid, which is guaranteed to be unique. – AL. Oct 24 '17 at 11:14
-1

i hope tis is helpful to

enter image description here

this is mydb in fcm

db structure in json like,

 walinnstracker{
    active_users{
          info{
               "count" : "13",
               "female_count" : "0"
               "male_count" : "0"
             }
               }

              }