skip to Main Content

I’m implementing push notifications using Firebase Cloud Messaging service in my app.

The approach I’m using is that I’m obtain the FCM token using library react-native-firebase – something like this:

const getToken = async () => {
  try {
    const token = await firebase.messaging().getToken();
    if (token) return token;
  } catch (error) {
    console.log(error);
  }
};

Afterwards, I’m sending the FCM tokens to my API so I know what users should receive the push notification.

However, the legacy API is being discontinued.

FCM legacy APIs for HTTP and XMPP should migrate to the HTTP v1 API
at the earliest opportunity. Sending messages (including upstream
messages) with those APIs was deprecated on June 20, 2023, and will be
removed in June 2024.

The official documentation for migrating from FCM APIs to HTTP V1 isn’t clear enough for me. Are these access tokens generated differently now? Seems like they do, and you should use a private key file in JSON format provided in your Firebase account.

My question is, how exactly do I generate the access tokens now. Will await firebase.messaging().getToken(); still retrive the correct token on HTTP v1 without me doing anything additional? Thank you.

2

Answers


  1. The key part on that is:

    Sending messages with those APIs was deprecated on June 20, 2023, and will be removed in June 2024

    So while sending messages will need to change to use the new endpoing, receiving messages (which is what the code in your React Native app does) will not change.

    Login or Signup to reply.
  2. I think that you’re confusing device tokens with access tokens.

    The code that you provided is how you mint device tokens on the client side using the react-native-firebase node package. These tokens are required for firebase to identify the user’s device and forward the notification accordingly. There has been no mention of change for this AFAIK.

    The tokens which are mentioned in the API upgrade notes are access tokens for authenticating with the messaging APIs in general (with or without device tokens). If you are interacting with these APIs via HTTP directly (no admin sdk), then you must follow the notes on that page for receiving and utilizing these new access tokens. If you use an admin SDK like I do, then a simple package upgrade and using new methods over deprecated ones is enough. No client side code change required.

    Took me 1 line of code to get it done.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search