Skip to content

Commit

Permalink
fix(messaging): deprecate onTokenRefresh(event => event.token) fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
Salakar committed Nov 25, 2019
1 parent 547d0a2 commit 1940d6c
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/messaging/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,21 @@ class FirebaseMessagingModule extends FirebaseModule {
// TODO(salakar) rework internals as without this native module will never be ready (therefore never subscribes)
this.native;

const subscription = this.emitter.addListener('messaging_token_refresh', listener);
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 = new String(token);
Object.defineProperty(tokenStringWithTokenAccessor, 'token', {
enumerable: false,
get() {
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();
}

Expand Down

0 comments on commit 1940d6c

Please sign in to comment.