I use the code below to obtain a token from firebase :
const messaging = firebase.messaging();
messaging.requestPermission()
.then(() =>{
return fi
I have an alternate solution to your problem,
You can use topics for receiving notifications,
1.) Subscribe topic for your registration_token, let the topic name unique for every user like user id.
https://iid.googleapis.com/iid/v1//rel/topics/
Example:
https://iid.googleapis.com/iid/v1/nKctODamlM4:CKrh_PC8kIb7O...clJONHoA/rel/topics/movies
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
2.) Send Notification to topic
https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{
"to" : "/topics/movies",
"priority" : "high",
"notification" : {
"body" : "This is a Firebase Cloud Messaging Topic Message!",
"title" : "FCM Message",
}
}
3.) Remove registration_id from the topic on logout
https://iid.googleapis.com/iid/v1:batchRemove
Content-Type:application/json
Authorization:key=API_KEY
{
"to": "/topics/movies",
"registration_tokens": ["nKctODamlM4:CKrh_PC8kIb7O..."],
}
Replace topic name "movies" with the unique user id or email etc