Within the library I am currently utilizing, there is a method called getToken which can be seen in the following example:
getApplicationToken() {
window.FirebasePlugin.getToken(function(token) {
console.log('Received FCM token: ' + token);
}, function(error) {
console.log('Failed to retrieve FCM token', error);
});
}
My goal is to create a method that directly returns the token itself. Here is what I have attempted:
async getApplicationTokenString(): Promise<string> {
return window.FirebasePlugin.getToken();
}
I then call this method using:
let firebaseToken = '';
this.fireBaseService.getApplicationTokenString().then(function(resolveOutput) {
firebaseToken = resolveOutput;
}, function(rejectOutput) {
console.log(rejectOutput);
});
Unfortunately, I only receive an output of Firebase token:
, without any actual value. However, when I use getApplicationToken, the FCM token is successfully logged.
How can I properly handle and pass the value obtained from an asynchronous promise?