getInstanceIdToken
should not report messaging/token-subscribe-failed
exceptions
#4909
Labels
getInstanceIdToken
should not report messaging/token-subscribe-failed
exceptions
#4909
Description
I was successfully using
@firebase/functions
in my application and recently added@firebase/messaging
. Everything works in development environment but when pushed to staging, I am gettingmessaging/token-subscribe-failed
error in my existing flows which were working with@firebase/functions
.It seemed like
functions
module is somehow accessingmessaging
module. After a close inspection and debugging, I found thatgetInstanceIdToken
is callingmessaging.getToken
.firebase-js-sdk/packages/functions/src/context.ts
Lines 86 to 104 in 9ec8ad5
I am not fully aware of the reasoning behind it but after reading the following comments
, I found an issue here. When I checked the control flow of this function. It looks like the control flow will never enter into the
catch
block because the return value ofmessaging.getToken
is a pending promise.Screenshots for Error Messages
Environment Configuration
v8.2.1
functions
andmessaging
servicesReproduce the Error
Once can directly identify this issue in
getInstanceIdToken
method offunctions
module with a simple control flow analysis.Here are some step to reproduce this inside an application
@firebase/functions
module and call anyhttpsCallable('<your_function>')
for your implementation@firebase/messaging
module following this tutorialNotifications
.httpsCallable('<your_function>')
) again. It will start throwingmessaging/token-subscribe-failed
. It works on your local development environment (as it was in my case), please deploy it to a custom domain (non-firebase).Suggest a Fix
This is a minor issue with the code and can be fixed with a simple
await
statement beforemessaging.getToken
callHere, the
await
will ensure that exceptions go to the catch statement.I am happy to contribute with a PR if this qualifies as an issue.
Please let me know if you need any more information regarding this issue. Also, please direct me if I am doing some wrong here.
The text was updated successfully, but these errors were encountered: