react-native-firebase
react-native-firebase copied to clipboard
onTokenRefresh crash the app for the first time
Hi, I moved to RN 61 and Firebase v6, IOS. In release mode my application crash when first time opened after install. I receive the following error in crashlytics log:
TypeError Properties can only be defined on Objects. defineProperty
After some debugging I found out the function that make the problem (react-native-firebase/messaging/index.js Object.defineProperty(tokenStringWithTokenAccessor):
`onTokenRefresh(listener) {
if (!isFunction(listener)) {
throw new Error("firebase.messaging().onTokenRefresh(*) 'listener' expected a function.");
}
const subscription = this.emitter.addListener('messaging_token_refresh', event => {
// TODO remove after v7.0.0, see: https://github.com/invertase/react-native-firebase/issues/2889
const { token } = event;
const tokenStringWithTokenAccessor = String(token);
Object.defineProperty(tokenStringWithTokenAccessor, 'token', {
enumerable: false,
get() {
// eslint-disable-next-line no-console
console.warn(
'firebase.messaging().onTokenRefresh(event => event.token) is deprecated, use onTokenRefresh(token => token) or call getToken() instead',
);
return token;
},
});
listener(tokenStringWithTokenAccessor);
});
return () => subscription.remove();
}`
And it's actually right, the token indeed is not an Object but string.
Is this any workaround for this?
Hey @lisichka999, just wondered if you managed to find a solution for this issue? 🤞