Skip to content
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

Unknown 5XX Error in Firebase Token Registration via react-native-firebase #8228

Closed
chaudharyDescendant opened this issue Jan 14, 2025 · 1 comment
Labels

Comments

@chaudharyDescendant
Copy link

Description

I am encountering an issue while using react-native-firebase in a React Native-based PWA. The workflow involves fetching the FCM token in the React Native repository using the getToken method and passing it to the React repository via a WebView. A register API is then called to register the token with Firebase and subscribe it to topics.

Issue Details:

  1. In more than 99% of cases, the register API successfully registers the FCM token with Firebase.
  2. However, in a small number of cases (<1%), the register API fails with an "Unknown Error" and a 5XX status code.
  3. I am relying on the token provided by the messaging().getToken() method.

Expected Behavior

The getToken method should always generate a valid token, and the token should register successfully with Firebase without causing 5XX errors.

Actual Behavior

In rare cases, the token provided by getToken results in a 5XX error when attempting to register it with Firebase via the register API.

Environment

"react-native": "0.68.6",
@react-native-firebase/app: "18.1.0"
@react-native-firebase/messaging: "18.1.0"
@react-native-firebase/analytics: "18.1.0"

Steps to Reproduce

  1. Use messaging().getToken() to fetch an FCM token.
  2. Pass the token to a WebView and call a backend register API to register it with Firebase.
  3. In most cases, the token registration works correctly.
  4. Occasionally, the register API fails with a 5XX error and no clear indication of the cause.

Javascript

Fetching FCM Token

export const getFcmToken = async () => {
try {
if (!messaging().isDeviceRegisteredForRemoteMessages) {
await messaging().registerDeviceForRemoteMessages();
}
const fcmToken = await messaging().getToken();
if (fcmToken) {
const tokenStorage = {
token: fcmToken
}
await AsyncStorage.setItem(FCM_CONSTANTS.FCM_TOKEN, JSON.stringify(tokenStorage));
}
} catch (err) {
console.error(err);
}
};

Registering Token

export const registerToken = async() => {
try {
const webView = getWebView();
const tokenRegistered = await AsyncStorage.getItem(FCM_CONSTANTS.FCM_TOKEN)
let obj = {
...JSON.parse(tokenRegistered!),
type: FCM_CONSTANTS.TOKEN,
deviceId: DeviceInfo.getDeviceId(),
}
if(webView) {
webView.injectJavaScript(window.postMessage('${JSON.stringify(obj) }');true;);
}
} catch (err) {
console.error(err);
}
}

Could there be an issue with how getToken generates tokens in rare cases? Please help if anyone ever faced such issue or could possible know how to resolve such type of issue.

@mikehardy
Copy link
Collaborator

Please don't report issues on old versions.
Update to current versions and attempt to reproduce
If you still reproduce, please log again but do not delete the template, rather, provide the information requested in the issue template when asking for help via an issue (makes sense, yes?)

Additionally, please grab device logs - for instance, when you reproduce on android include relevant parts of adb logcat

If you cannot reliably reproduce, we will not be able to reliably help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants