Skip to content

[🐛] getToken() returns not valid FCM token on IOS after deleteToken() #4571

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

Closed
1 of 9 tasks
mkuligowski opened this issue Nov 18, 2020 · 18 comments
Closed
1 of 9 tasks
Labels
help: needs-triage Issue needs additional investigation/triaging. Keep Open avoids the stale bot platform: ios plugin: messaging FCM only - ( messaging() ) - do not use for Notifications type: bug New bug report Workflow: Needs Review Pending feedback or review from a maintainer.

Comments

@mkuligowski
Copy link

Issue

In our application we use firebase messaging to communicate with the logged in user, therefore we call getToken() after the user logs in or in App.js after opening the application if the user is already logged in. If the user logs out of the application, we call deleteToken().

On Android, every time we call getToken() after deleteToken(), a new token is generated, which we save on our backend and use it to send messages. However, on IOS, in the same scenario, a new token is not generated, but the old token is returned, so when we try to send a message from our backend, we get the error "Request entity not found". Is this an intended action? Should I generate a token for different users in different scope?


Project Files

Javascript

Click To Expand

package.json:

{
  "name": "app",
  "version": "0.1.0",
  "description": "App",
  "scripts": {
    "start": "react-native start",
    "tsc": "tsc -p ./tsconfig.json",
    "tsc:dev": "tsc -w -p ./tsconfig.json",
    "android": "react-native run-android --no-jetifier",
    "ios": "react-native run-ios",
    "lint": "npm run tsc && npm run eslint && npm run stylelint",
    "stylelint": "stylelint \"components/**/*.tsx\"",
    "eslint": "eslint . --ext .ts --ext .tsx --ext .js --fix",
    "prettier": "prettier ./**/*.tsx ./**/*.ts ./**/*.js --list-different  || (echo '\nPlease run the following command to fix:\nnpm run prettier:fix\n'; exit 1)",
    "prettier:fix": "prettier ./**/*.tsx ./**/*.tsx ./**/*.ts ./**/*.js --write",
    "pre-commit": "lint-staged",
    "test": "jest",
    "test:dev": "jest --watch",
    "test:coverage": "jest --coverage",
    "postinstall": "patch-package && jetify"
  },
  "lint-staged": {
    "*.{tsx,ts,js}": [
      "npm run lint",
      "git add"
    ]
  },
  "husky": {
    "hooks": {
      "pre-commit": "npm run pre-commit"
    }
  },
  "dependencies": {
    "@dooboo-ui/native-switch-toggle": "0.4.0",
    "@ptomasroos/react-native-multi-slider": "2.2.2",
    "@react-native-community/async-storage": "1.7.1",
    "@react-native-community/cameraroll": "2.0.0",
    "@react-native-community/google-signin": "4.0.3",
    "@react-native-community/image-editor": "2.3.0",
    "@react-native-firebase/app": "8.0.0",
    "@react-native-firebase/messaging": "7.2.1",
    "@types/lodash": "4.14.149",
    "@types/ptomasroos__react-native-multi-slider": "0.0.1",
    "@types/react-native-calendars": "1.20.8",
    "@types/react-native-fbsdk": "1.1.0",
    "@types/react-native-push-notification": "5.0.2",
    "@types/react-native-share": "3.3.0",
    "@types/react-redux": "7.1.5",
    "@types/sockjs-client": "1.1.1",
    "@types/stompjs": "2.3.4",
    "@types/styled-components": "4.1.19",
    "@types/uuid": "3.4.6",
    "@types/yup": "0.26.30",
    "axios": "0.19.0",
    "camelcase-keys": "6.1.1",
    "esm": "3.2.25",
    "formik": "2.1.4",
    "geolib": "3.3.1",
    "i18next": "19.0.2",
    "libphonenumber-js": "1.7.53",
    "lodash": "4.17.15",
    "moment": "2.24.0",
    "net": "1.0.2",
    "numbro": "2.3.1",
    "polygon-clipping": "0.15.1",
    "rbush": "1.4.3",
    "react": "16.9.0",
    "react-dom": "16.8.6",
    "react-i18next": "11.2.7",
    "react-native": "0.61.5",
    "react-native-branch": "5.0.0-beta.1",
    "react-native-calendars": "1.300.0",
    "react-native-camera": "3.23.1",
    "react-native-config": "0.12.0",
    "react-native-confirmation-code-field": "4.1.0",
    "react-native-device-info": "5.6.1",
    "react-native-draggable-flatlist": "2.4.0",
    "react-native-fbsdk": "2.0.0",
    "react-native-fs": "2.16.6",
    "react-native-geocoding": "0.4.0",
    "react-native-geolocation-service": "4.0.0",
    "react-native-gesture-handler": "1.6.1",
    "react-native-gifted-chat": "0.16.0",
    "react-native-highlight-words": "1.0.1",
    "react-native-image-crop-picker": "0.28.0",
    "react-native-image-resizer": "1.2.1",
    "react-native-image-size": "1.1.3",
    "react-native-linear-gradient": "2.5.6",
    "react-native-map-clustering": "3.1.2",
    "react-native-maps": "0.27.1",
    "react-native-masked-text": "1.13.0",
    "react-native-modal": "11.4.0",
    "react-native-permissions": "2.1.5",
    "react-native-picker-select": "6.3.3",
    "react-native-push-notification": "5.1.0",
    "react-native-reanimated": "1.9.0",
    "react-native-redash": "12.6.0",
    "react-native-safe-area-context": "3.1.7",
    "react-native-screens": "1.0.0-alpha.22",
    "react-native-share": "4.0.1",
    "react-native-splash-screen": "3.2.0",
    "react-native-status-bar-height": "2.5.0",
    "react-native-svg": "9.9.9",
    "react-native-swipe-gestures": "1.0.5",
    "react-native-swipe-list-view": "2.1.3",
    "react-native-text-size": "4.0.0-rc.1",
    "react-native-web": "0.11.4",
    "react-navigation": "4.0.6",
    "react-navigation-stack": "1.8.0",
    "react-navigation-transitions": "1.0.12",
    "react-redux": "7.1.3",
    "recyclerlistview": "3.0.0",
    "reduce-reducers": "1.0.4",
    "redux": "4.0.4",
    "redux-devtools-extension": "2.13.8",
    "redux-persist": "6.0.0",
    "redux-thunk": "2.3.0",
    "rn-fetch-blob": "0.12.0",
    "rn-sliding-up-panel": "2.4.2",
    "sockjs-client": "1.4.0",
    "stompjs": "2.3.3",
    "styled-components": "4.4.0",
    "uuid": "3.3.3",
    "yup": "0.28.1"
  },
  "devDependencies": {
    "@babel/core": "7.6.2",
    "@babel/runtime": "7.6.2",
    "@react-native-community/eslint-config": "1.1.0",
    "@testing-library/jest-native": "3.0.2",
    "@testing-library/react-native": "4.0.14",
    "@types/jest": "24.0.18",
    "@types/react": "16.8.23",
    "@types/react-native": "0.57.65",
    "@types/react-test-renderer": "16.8.3",
    "@types/redux-mock-store": "1.0.2",
    "@typescript-eslint/eslint-plugin": "2.34.0",
    "@typescript-eslint/parser": "2.34.0",
    "babel-jest": "24.9.0",
    "eslint": "6.5.1",
    "eslint-config-prettier": "6.11.0",
    "eslint-config-react-app": "5.2.1",
    "eslint-plugin-flowtype": "5.1.3",
    "eslint-plugin-import": "2.20.2",
    "eslint-plugin-jsx-a11y": "6.2.3",
    "eslint-plugin-react": "7.20.0",
    "eslint-plugin-react-hooks": "4.0.8",
    "husky": "3.0.5",
    "jest": "24.9.0",
    "jest-date-mock": "1.0.8",
    "jest-svg-transformer": "1.0.0",
    "lint-staged": "9.3.0",
    "metro-react-native-babel-preset": "0.56.0",
    "patch-package": "6.2.2",
    "prettier": "2.0.5",
    "react-native-svg-transformer": "0.13.0",
    "react-test-renderer": "16.9.0",
    "redux-mock-store": "1.5.4",
    "stylelint": "11.1.1",
    "stylelint-config-prettier": "8.0.2",
    "stylelint-config-standard": "19.0.0",
    "stylelint-config-styled-components": "0.1.1",
    "stylelint-processor-styled-components": "1.8.0",
    "ts-jest": "24.1.0",
    "typescript": "3.8.3"
  },
  "private": true
}

firebase.json for react-native-firebase v6:

# N/A

iOS

Click To Expand

ios/Podfile:

  • I'm not using Pods
  • I'm using Pods and my Podfile looks like:
# N/A

AppDelegate.m:

// N/A


Android

Click To Expand

Have you converted to AndroidX?

  • my application is an AndroidX application?
  • I am using android/gradle.settings jetifier=true for Android compatibility?
  • I am using the NPM package 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:

System:
    OS: Linux 5.4 elementary OS 5.1.7 Hera
    CPU: (8) x64 Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
    Memory: 297.82 MB / 15.41 GB
    Shell: 4.4.20 - /bin/bash
  Binaries:
    Node: 12.16.1 - ~/.nvm/versions/node/v12.16.1/bin/node
    npm: 6.13.4 - ~/.nvm/versions/node/v12.16.1/bin/npm
  IDEs:
    Android Studio: 3.6 AI-192.7142.36.36.6392135
  npmPackages:
    react: 16.9.0 => 16.9.0 
    react-native: 0.61.5 => 0.61.5

  • Platform that you're experiencing the issue on:
    • [X ] iOS
    • Android
    • iOS but have not tested behavior on Android
    • Android but have not tested behavior on iOS
    • Both
  • react-native-firebase version you're using that has this issue:
    • e.g. 7.2.1
  • Firebase module(s) you're using that has the issue:
    • messaging
  • Are you using TypeScript?
    • Y & 3.8.3


@mkuligowski mkuligowski added help: needs-triage Issue needs additional investigation/triaging. type: bug New bug report labels Nov 18, 2020
@mikehardy
Copy link
Collaborator

Hi there! This is not intended or expected, but can you reproduce it still with v10 of react-native-firebase?


    "@react-native-firebase/app": "8.0.0",
    "@react-native-firebase/messaging": "7.2.1",

@mkuligowski
Copy link
Author

@mikehardy yep still the same after upgrading to v10

@mikehardy
Copy link
Collaborator

Well that's unfortunate - thanks for checking, this will likely be an upstream issue - the surest course to resolution will be to do a quickstart reproduction based on: https://github.com/firebase/quickstart-ios/tree/master/messaging (or perhaps even https://github.com/firebase/quickstart-ios/tree/master/installations as I think it is the underlying provider of tokens?) with exact steps / iOS versions etc to reproduce

@michaelyav
Copy link

Any workaround so far? Unfortunately, we got stuck with this problem as well.

@mikehardy
Copy link
Collaborator

All information will be present on this issue assuming it is referenced if there is an issue logged upstream - what you see is what we know (not a lot unfortunately) - it needs someone from the community to dig in for triage

@Chachaproper
Copy link

Same problem.
This works for me: #3714 (comment) and #3714 (comment)

deleteToken(undefined, '*')
getToken(undefined, '*')

getToken never resolve a promise if call it without arguments after deleteToken(undefined, '*')

@mikehardy
Copy link
Collaborator

@Chachaproper thank you so much for cross-linking that, I had forgotten that. @michaelyav / @mkuligowski this may be thing you need, and we likely need to integrate it into our code as the default (I don't believe there is a PR pending for this, if not and it is confirmed as working we would welcome one and I'd help get it merged + released)

@SnaiNeR
Copy link

SnaiNeR commented Dec 10, 2020

@Chachaproper thank you man ! i spended a lot of time to find out what the f*ck is happening there >_<

@stale
Copy link

stale bot commented Jan 10, 2021

Hello 👋, to help manage issues we automatically close stale issues.
This issue has been automatically marked as stale because it has not had activity for quite some time. Has this issue been fixed, or does it still require the community's attention?

This issue will be closed in 15 days if no further activity occurs.
Thank you for your contributions.

@stale stale bot added the Type: Stale Issue has become stale - automatically added by Stale bot label Jan 10, 2021
@mikehardy mikehardy added platform: ios plugin: messaging FCM only - ( messaging() ) - do not use for Notifications Workflow: Needs Review Pending feedback or review from a maintainer. Keep Open avoids the stale bot and removed Type: Stale Issue has become stale - automatically added by Stale bot labels Jan 19, 2021
@helenaford
Copy link
Member

@Chachaproper I don't see any difference with passing params to getToken, they're needed for deleteToken on iOS but getToken with no params still does the trick from what I've been able to reproduce, e.g.:

deleteToken(undefined, '*')
getToken()

@tomwanzek
Copy link

First of all, thanks for all the hard work on this library 😄

However, having spent several days trying to pin down the issue with our "flaky" push notification behaviour with tediously running differential diagnostic scenarios using FCM console and quadruple checking our systems integration and SDK usage, everything just boiled down to this issue.

At this point (and seeing that #3714 has already been closed, I am left wondering, what the "official" solution is at this point?

  • Is there going to be a forthcoming fix? Or
  • Is deleteToken(undefined, '*') the magic workaround fix on a permanent basis?

If the latter is the case, it would be great, if the SDK documentation receives an overhaul to prominently call out this issue and the proposed workaround, so that others don't lose valuable time and hair on a known behaviour that really flies under the radar. 🙇‍♂️

@mikehardy mikehardy pinned this issue Mar 31, 2021
@mikehardy
Copy link
Collaborator

Oh no - I'm so sorry that wasted so much time @tomwanzek - I've pinned this issue to the top of the repo's issue list so it has a lot more visibility, it's already marked for review just not enough time yet to get to it yet. If there is not a real fix there should definitely be something in the documentation

That said - as someone who was just up and down the documentation looking for why you were having problems you probably have a pretty good idea where it's missing (maybe in multiple spots - like the tips and tricks page, the usage page and the API documentation...I'm not sure what's best) - there should be an edit button at the top right of every page and if you made a quick PR on any of them that seemed like a good spot I'd merge it immediately

@tomwanzek
Copy link

@mikehardy My apologies, but I did not yet have a chance to cycle back to creating possible additional documentation.

However, we seem to have run into a somewhat more severe unintended consequence of the proposed workaround. To explain.

When the App is started from Quit state, the splash screen is shown and as soon as possible, the log in screen. We are using chained messaging().requestPermission() and messaging().getToken(), valid permissions assumed, as part of our app initialization logic following sign in and obtaining a session token.

When the user signs out we are using messaging().deleteToken(undefined, "*"), as per the "workaround for this bug.

If the user signs out and then and then quits the app, everything works normally, when the user opens the app and signs in the next time.

However, if the user signs out, which bring them back the the sign in screen, and instead of quitting the app, signs back in: The app will hang at messaging().getToken() which never resolves.

The only recovery we currently have for the user is to quit the app in that "hanging" state and open it up again. Interestingly, returning from quit state everything will work as expected again.

@mikehardy
Copy link
Collaborator

That sounds like something I would try to minimally reproduce using only the native sdks from the Quickstart on the affected mobile operating system, but I'd first make sure that everything was at latest version. There have been new releases of everything since last contact on this one

@tomwanzek
Copy link

We are current w.r.t. Firebase, i.e. RN Firebase SDK for app, analytics and messaging are on 11.4.1.

Given that this issue is still open, I am assuming no fix has been part of any recent releases, which would allow us to return to a simple, yet fully functional use of deleteToken() without arguments.

I will see, if/when I have some time to look into creating a minimal repro repo. Have to prioritize core project needs since in the past 1 1/2 weeks a couple of other 3rd party library issues have impacted our builds.

@mikehardy
Copy link
Collaborator

mikehardy commented May 10, 2021

your assumptions sound correct - no progress on this one as a viable workaround (modulo a failure to resolve promise of course) puts it behind tracking core functionality breaking changes with the native SDKs and we have a more-than-full plate on that unfortunately

@tomwanzek
Copy link

tomwanzek commented May 10, 2021

@mikehardy Thanks for the update! Really appreciate the transparency, at least it gives us something to prioritize against as well 😄

@mikehardy mikehardy unpinned this issue May 12, 2021
@mikehardy
Copy link
Collaborator

I believe this is fixed in v12 just released - can reopen if not

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help: needs-triage Issue needs additional investigation/triaging. Keep Open avoids the stale bot platform: ios plugin: messaging FCM only - ( messaging() ) - do not use for Notifications type: bug New bug report Workflow: Needs Review Pending feedback or review from a maintainer.
Projects
None yet
Development

No branches or pull requests

7 participants