React-native-firebase: Cannot read property 'appName' of undefined

Created on 28 May 2020  路  6Comments  路  Source: invertase/react-native-firebase

Using below code to revoke token on logout but gives 'appName' undefined

const authorizedEntity = firebase.iid().app.options.messagingSenderId;
firebase.iid().deleteToken(authorizedEntity, '*').then(nullToken => nullToken);
No Template

Most helpful comment

@codemeall, I have same issue. To fix this I use postinstall script

sed -i .bak -e 's/nativeEmitter.addListener(eventName, event => {/nativeEmitter.addListener(eventName, event => {if (!event) return;/g' ./node_modules/react-native-firebase/dist/utils/events.js

It just checks if event is undefined and skips this function. I am not sure that solution is right, but it works for me.

@mikehardy my environment is:

"react": "16.9.0",
"react-native": "0.61.2",
"react-native-firebase": "5.6.0" // same issue with "5.5.6"

All 6 comments

No template

@codemeall, I have same issue. To fix this I use postinstall script

sed -i .bak -e 's/nativeEmitter.addListener(eventName, event => {/nativeEmitter.addListener(eventName, event => {if (!event) return;/g' ./node_modules/react-native-firebase/dist/utils/events.js

It just checks if event is undefined and skips this function. I am not sure that solution is right, but it works for me.

@mikehardy my environment is:

"react": "16.9.0",
"react-native": "0.61.2",
"react-native-firebase": "5.6.0" // same issue with "5.5.6"

@ownikss I had the same issue and your fix works. I suppose the question is why the event is null if it should always have an appName. The eventName in question (for me, anyways) is messaging_token_refreshed.

P.S. @mikehardy I am also using the deprecated 5.6.0 version (rn 0.62.2) as I need foreground iOS notifications (6.x don't work for me). I assume since it's the deprecated version this might not be a valid concern but if nothing can be done about the issue at least mentioning it in the docs would be good enough.

Also running into this with RNF 5.6.0 + RN 0.62.2, using @ownikss fix with ds300/patch-package

@ownikss your solution prevents the event from firing if data is undefined

A better solution would be:
sed -i .bak -e 's/if (event.appName) {/if (event?.appName) {/g' ./node_modules/react-native-firebase/dist/utils/events.js

so if the event data was undefined it would still emit the event. This way you don't interfere with the intricate inner-workings of invertase code.

...combined with https://github.com/ds300/patch-package to make the change permanent for you

Was this page helpful?
0 / 5 - 0 ratings