I am doing something similar already, however, it doesn't solve the problem I highlighted. I also wonder how others are doing this.
The issue is with persisting IID to server. If I persist the IID in the else block, it means I'll be persisting it on every page load. Not ideal.
Another approach is to save the state in localStorage and then check if the state changed in which case I send a request to the server to persist IID. Something like this would have been better handled by through the FCM library itself since this is a shared problem.
This seems like a very common use case. How do others tackle this?
Aleem