-
Notifications
You must be signed in to change notification settings - Fork 2.3k
InvalidRegistration error on fcm token #3476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
You should try the |
Hi! This issue is still actual on iOS for versions 6.4.1-alpha.0 (@next) and 6.7.1. I don't have any issue with Android. I struggled with this these days and noticed it happens as soon as the auth module is installed (works perfectly fine when auth module is not installed). The issue happens even without any import and use of the auth module, just installing it. Description: the messaging device token seems to get randomly unregistered, most likely when closing the app by swiping it away. It happens around 50% of the time when closing app. Then the server app (nodejs with 'firebase-admin' lib for me) fails to send its next message with error: errorInfo: {
code: 'messaging/invalid-registration-token',
message: 'Invalid registration token provided. Make sure it matches the registration token the client app receives from registering with FCM.'
} and all following messages with: errorInfo: {
code: 'messaging/registration-token-not-registered',
message: 'The provided registration token is not registered. A previously valid registration token can be unregistered for a variety of reasons. See the error documentation for more details. Remove this registration token and stop using it to send messages.'
} (I am 100% confident there is no mistake with the token on server side - it's exactly the same token and it suddenly stops working) Tested with :
index.js: /**
* @format
*/
import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import notifee, { Importance } from '@notifee/react-native';
import messaging from '@react-native-firebase/messaging';
function onMessageReceived(message) {
notifee.displayNotification(JSON.parse(message.data.notifee));
}
messaging().onMessage(onMessageReceived);
messaging().setBackgroundMessageHandler(onMessageReceived);
async function onAppBootstrap() {
await messaging().registerDeviceForRemoteMessages();
const channelId = await notifee.createChannel({
id: 'default',
name: 'Default Channel',
importance: Importance.HIGH,
});
}
notifee.onBackgroundEvent(async ({ type, detail }) => {
const { notification, pressAction } = detail;
// do nothing for now
});
onAppBootstrap();
AppRegistry.registerComponent(appName, () => App); Unfortunatly its making messaging module quite unsuable for iOS in my case. If you have any suggestion or need more info I'm here. |
Can you try setting up a token refresh listener? https://rnfirebase.io/reference/messaging#onTokenRefresh Auth maybe causing this to refresh on "some event". |
Hi, so I tried setting up onTokenRefresh but I get an error everytime it's called, on both iOS and Android. The same error as reported in this issue : #3556 onTokenRefresh seems to be called at the first launch of the app, and then each time the messaging token is unregistered, e.g : I made a public repo if you want to check my complete code, I only removed GoogleService-Info.plist and notifee.config.json: |
Do we have any updates on this issue? I have the same issue with @romainmarchand. |
We are getting same issue here, any update on that? |
@AnhVu23 @dan-arkhipov (from @romainmarchand) |
@rm167 We have issues with iPhone X and XR. After updating to newest firebase version, the function onTokenRefresh seems to work, but I sometimes get the error (like 10% of total tests). |
Ok, I guess it can occur on any kind of iPhone then. I am still having the invalid registration error as well for last versions: |
I am testing on iPhone SE (iOS 13.4) and having an invalid registration error for the latest version. |
@mikehardy by any chance you know if this issue could be prioritized or suggest a workaround in the meantime? This seems like it is blocking quite a lot of people now. |
Sorry - I have no say in priorities other than when I go to fix things that directly affect me, and this one hasn't (yet) so I haven't put any effort into it |
@mikehardy we are happy to have a look, however we never had experience contributing before. Could you please guide us where do we start to look in order to tackle this problem effectively? |
I think the best way to start is probably just to assume that all the code in node_modules/@react-native-firebase/* is your code too. You can go in there and instrument all you want, add debug statements all you want, breakpoints etc. So I'd take all the parts of code in there that wrap upstream SDK statements and at minimum I'd add log statements that show the current state of all objects going in to and coming out of the API calls to make sure things matched expectations Note that 'patch-package' can be very useful for this as it can persist your Obj-C changes into git and they can be reproduced across all developer and CI machines so things are stable and you don't have some magic troubleshooting machine where the special code is |
@mikehardy thanks for that, given you are well familiar with the product, could you please direct us where exactly we should start looking in the code at the first place. We think that something invalidates the token or when token gets refreshed our .onTokenRefresh method is not firing. |
@dan-arkhipov Yesterday I looked into Auth module's index.js file (https://github.com/invertase/react-native-firebase/blob/master/packages/auth/lib/index.js) and noticed that the token wasn't unregistered anymore when commenting out some lines (but background messaging was not working either...), but the thing is that debugging iOS is a real pain for me (because I don't actually own a mac: I just use a slow remote mac, and I have to archive at every build, so it take's almost 1 hour and I can't get my real phone's logs). So I wasn't able to precisely find which part of the code is causing the issue and gave up for now. But if your mac setup is better than mine, maybe you could start by commenting out stuff in this file (like event listeners or other files imports). Just a suggestion though, I don't know much about how the library works... There's also this file from messaging module, with a reference to Auth module at line 103 : https://github.com/invertase/react-native-firebase/blob/master/packages/messaging/ios/RNFBMessaging/RNFBMessaging%2BAppDelegate.m I wonder if some part of messaging is handled by Auth module instead of Messaging module (as soon as Auth module is installed). If it's the case, it might be because of the phone number authentication process, that uses silent notifications. But again, just wild thoughts.. |
@romainmarchand do you know if there is an official process in iOS to invalidate a token? I wonder if we can reverse engineer it by finding a method that does the invalidation and work backwards. I can try to debug that and post here my findings here. Please feel free to suggest a few more things I should try to do. |
About invalidation, I don't know...
|
Hello 👋, to help manage issues we automatically close stale issues.
|
I am having the same problem on iOS. When a token is generated it works fine, but when I close/reopen the app several times and send push during this process, it gets a previous token but for some reason it is invalid, even though it is returned by the This almost always happens in this flow, and on this order: -Push sent correctly (First request):-InvalidRegistration Error (Second request, after closing and reopening the app a few times and opening it though notification)-Not registered Error (Third request made, just after the second one)From now on, all requests will return After some action of close/open the app, a new token is generated and returned by the Observations:
|
Apparently this problem just happen on iOS if I am running on the release scheme of XCode. I released a new AdHoc version on AppCenter and the app stopped having the refresh token problem, maybe is something related to the Metro Bundler of RN or something related to the APNs key, I don't know... Apple stuff is just terrible to debug since it existence. |
I am facing this on iOS only, android is fine. Worked without issue in the 5x days, followed upgrade paths to 6x and running into this. For now i am trying what @romainmarchand suggested and removing the auth module to see if that yields any result. So far initial pushes work. Will exit the app and periodically test throughout the day. fingers crossed we can narrow down an area to focus on to resolve this. |
Update from me, after 2 days with the auth module omitted as per @romainmarchand suggested i am not receiving those fcm dropouts and the device gets every push note. I'll give it another day then will try re-adding auth again to prove that is where an issue may lie. |
Hey @devpascoe thank you very much for your input. Could you please let us know more what changes have you done and which files you have commented out? Does it have effect on authentication?
Thank you |
I am not sure why but it seems to work fine for me now. I choose another type of distribution for the archive, as @roni-castro suggested. I used to choose "Development - Distribute to members of your team." (signed with development certificate). Now I distribute with App Store Connect (distribution certificate) and I test with "Test Flight", and the issue doesn't occur anymore. |
Also seeing nightmare-ish inconsistency. This only happens for me on our app center build. Never locally, in debug mode.
|
Hello 👋, to help manage issues we automatically close stale issues.
|
Closing this issue after a prolonged period of inactivity. If this is still present in the latest release, please feel free to create a new issue with up-to-date information. |
Happened consistantly that after the first initial iOS notification was received that the token become invalid. Publishing it on testflight with the production cert the notifications were received everytime. |
This is currently happening to our production app with
This is affecting a large number of our users fcmTokens. Ran a
@romainmarchand did you manage to get anywhere with the issue you were encountering? |
Hi @dooleyb1, I don't work on this anymore, but after my last message this issue didn't occur again for me (using App Store Connect). |
@dooleyb1 Is the issue resolved? |
Not particularly, I've decided to just presume that these users with |
Any Solutions? |
Try to remove |
i am still receiving this , can anyone please help me? |
@stackcru-tech the first step to receiving help is to make sure you're on current stable versions, there is no telling how many issues have been found and resolved between your versions and v11.4.1 (current stable) But the upgrade process itself isn't that hard! check the changelogs of the app auth and messaging packages for breaking changes until we hit v10, then all the changelog notes are in the main changelog - and there really aren't that many changes, we are just really strict on making a major version if there is any breaking change at all - https://invertase.io/blog/react-native-firebase-versioning |
@mikehardy i am upgrading the versions to the latest stable version, 11.4.1 |
Probably need fresh Google plist and json coming from the versions you had, also enable devicecheck API (check firebase android auth docs) |
@mikehardy I had done this but still facing the same issue. |
You may want to open a new issue with full details vs posting on an old one but I can attest 100% that it works. The module works. So you have something project-specific and it will likely then not get a huge amount of priority as it will not result in any change in the module. |
can you please let me now why this issue occurs? |
@mikehardy i am also facing this, i had check all the logs in abd Firebase Installations Service is unavailable. Please try again later. |
@stackcru-tech I can't tell you why it is happening for your project, no. I can say that your versions were old enough you should look at it almost as a completely fresh integration and re-read the docs from that perspective. I also encourage you to try a fresh playground / toy app as a proof of concept it works, and I have a script that generates a full example skeleton so you may do so easily https://github.com/mikehardy/rnfbdemo/blob/master/make-demo.sh I'm sorry you're having a difficult time with the upgrade, I know that is frustrating. But something is wrong with your project from the perspective of current firebase native libraries and you'll just have to slowly work through things to figure out what |
Can anyone explain, why it is working in production build and not development build? Here are configuration at my side: React native: although it is working fine in testflight, but still want to know, if we missed any configuration, that's why it is not working in development builds. |
I have the same issue “token become invalid” after first time received notification but after uninstall @react-native-firebase/analytics every working fine. If I’m not mistaken there is an open issue regarding this problem. |
@roni-castro Have you found solution for this issues? |
Issue
Getting InvalidRegistration while sending fcm message.
On the App side, it is configured as per the setup guide.
Above give us the fcm token which we are sending to the Firestore and a could function send the fcm message. But sometimes it works and sometimes it sends InvalidRegistration.
Project Files
Javascript
Click To Expand
package.json
:firebase.json
for react-native-firebase v6:# N/A
iOS
Click To Expand
ios/Podfile
:# N/A
AppDelegate.m
:// N/A
Android
Click To Expand
Have you converted to AndroidX?
android/gradle.settings
jetifier=true
for Android compatibility?jetifier
for react-native compatibility?android/build.gradle
:// N/A
android/app/build.gradle
:// N/A
android/settings.gradle
:// N/A
MainApplication.java
:// N/A
AndroidManifest.xml
:<!-- N/A -->
Environment
Click To Expand
react-native info
output:react-native-firebase
version you're using that has this issue:e.g. 5.4.3
Firebase
module(s) you're using that has the issue:e.g. Instance ID
TypeScript
?Y/N
&VERSION
React Native Firebase
andInvertase
on Twitter for updates on the library.The text was updated successfully, but these errors were encountered: