@indoomni/strapi-plugin-firebase-admin

1.0.6 • Public • Published

🚀 Getting started with Strapi

Wrapper for google-wombot's Firebase Admin Node.js SDK library to be used with Strapi apps. You are going to need a Google Firebase service account credential file (for more information, head on to https://firebase.google.com/). The Strapi app will be able to send push notification to clients reporting their FCM token, do analytics and stuff.
Note: As of the time of writing this document, only the push notification has been implemented.
Save the FCM token of each client on login, register, or some other onboarding scheme you may have setup.

Installation

Add the library to your Strapi project. Learn more


yarn add @indoomni/strapi-plugin-firebase-admin
yarn install
yarn build


Configuration

Add the following configuration attributes to your server.js.


# config/server.js or config/env/**/server.js
# -------------------------------------------

module.exports = ({ env }) => ({
  host: env('HOST'),
  port: env.int('PORT'),
  app: {
    env: env('ENV'),
    name: env('APP_NAME'),
    keys: env.array('APP_KEYS'),
  },
  // ...
  'firebase-admin': {
    enabled: true,
    config: {
      configFile: '../service-account.json',
      clientId: `${env('APP_NAME')}_${env('ENV')}_fcm`,
      services: ['notification'],
      tags: [],
      test: {
        token: 'xyz123',
        title: 'Hello!',
        body: 'Hello world!',
      },
    },
  },
  // ...
});

Notice config sub-attribute in the the 'firebase-admin' attribute. Don't forget to use the single-quotation marks.

Now, notice the configFile attribute. Your service account JSON file should reside on the root of your project (add "../" since we use "src" for the base directory). The other attributes are currently ignored and supplied for future development. If you supply a test attribute, the library will try to send a message to the said token after initialized.


How to send messages

Anywhere in your code, write as in the following snippet. Refer to the admin controller inside the library, and call send function. Supply a client's FCM token, title, body and data if necessary.
Note: If you specify [data], it will be encrypted as Base64 string. At your client app's side, when you receive the notification, decode the data using some Base64 encryption, then use the data as needed.


# src/**/any.js
# ------------------------------

// ...
try {
  await strapi
    .plugin('firebase-admin')
    .controller('admin')
    .send(token, title, body, data);
} catch (err) {
  strapi.log.debug('📺: ', err);
}
// ...


📚 Learn more



Feel free to check out my GitHub repository. Your feedback and contributions are welcome!

Package Sidebar

Install

npm i @indoomni/strapi-plugin-firebase-admin

Weekly Downloads

0

Version

1.0.6

License

MIT

Unpacked Size

11.8 kB

Total Files

15

Last publish

Collaborators

  • iman.sjamhudi