-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Description
Hello,
I recently ran into this issue. I was attempting to get the current token for the user on the service worker.
My code on the service worker:
`firebase.initializeApp({
'messagingSenderId': '-'
})
let messaging = firebase.messaging();
let token = await messaging.getToken()
console.log(token);
`
My Code on the prompt event in the windowed webpage:
var config = { apiKey: "-", authDomain: "-", databaseURL: "-", projectId: "-", storageBucket: "", messagingSenderId: "-" }; firebase.initializeApp(config); messaging.requestPermission() .then(function () { getCurrentToken(); } //After user allows notifications function getCurrentToken(){ // Retrieve Firebase Messaging object. const messaging = firebase.messaging(); messaging.getToken() .then(function (currentToken) { console.log(currentToken); } }
Both calls gives me different
The interesting thing is if I use either token to send the notification to the client, it also works.
My question is why is there two different tokens from the initial allow event to the service worker on receive event. Is there something I am doing incorrectly? or is this an intended behavior.
Thanks in advance for your response.