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

Firebase integration problem #805

Closed
ykolomiets opened this issue Mar 9, 2018 · 6 comments
Closed

Firebase integration problem #805

ykolomiets opened this issue Mar 9, 2018 · 6 comments

Comments

@ykolomiets
Copy link

ykolomiets commented Mar 9, 2018

Hi! I have a mysterious issue. I want to use firebase-admin package in my project.

  • What I have done:
  1. npm install firebase-admin --safe
  2. In sandbox.js added 'firebase-admin'
  3. Initialization of firebase works fine and sending messages one by one works too.
  • Problem:

On this code:

let admin  = api.firebaseAdmin;
let ids = ['id1', 'id2'];
try 
   {
     admin.messaging()
       .sendToDevice(ids, message)
       .then((response) => {
         console.log(response);
       })
       .catch((err) => {
         console.log("Catched error: " + err);
       });
   } catch (err) {
     console.log(err);
   };

receive 'Error: Registration token(s) provided to sendToDevice() must be a non-empty string or a non-empty array.'

And this happens because in function sendToDevice presents check (ids instanceof Array) and it returns false. This problem is mysterious to me because if I check (ids instanceof Array) right before passing ids to sendToDevice it returns TRUE, but in function sendToDevice same check returns FALSE.

  • P.S.
    If I don't use impress and just create an empty folder, (npm install firebase-admin --safe), create file test.js, insert same code, node test.js - it works fine, without such error.
@belochub
Copy link
Member

Hello!
This happens due to the fact that impress runs the user's code sandboxed, meaning that in your case it runs your code and the code from firebase-admin package in different contexts and, therefore, global Array objects differ from each other, which means that instanceof operator returning false value is a correct result in this situation. This could have been easily avoided if firebase-admin developers used the relatively new Array.isArray method when possible (since it works in such situations) instead of using instanceof operator. You can also check out this discussion for a more detailed explanation.

There is nothing we can do about it, since sandboxing the code is one of the core ideas of impress, and I think you should report this issue to firebase-admin package developers instead, or you may even make a contribution to their package since this is quite easy to fix.

@tshemsedinov
Copy link
Member

tshemsedinov commented Mar 12, 2018

By the way, you don't need firebase at all :)

@tshemsedinov tshemsedinov reopened this Mar 12, 2018
@ykolomiets
Copy link
Author

ykolomiets commented Mar 12, 2018

why not? we use it for push notifications. Single interface for multiple platforms(iOS / Android). What are the alternatives? @tshemsedinov

@tshemsedinov
Copy link
Member

@ykolomiets you can use JSTP, Websocket or SSE to push event from server to client. It is implemented in impress and available without any extensions.

@ykolomiets
Copy link
Author

ykolomiets commented Mar 12, 2018

How can I push notifications to the app which is closed and connection with impress server isn't established? For this purposes Apple provides APN and Google provides its own service. Firebase is just a wrapper around these two services, so it's easy to use

@tshemsedinov
Copy link
Member

Use two different push services for those platforms, it's just twice harder. Using firebase for this more then twice harder ) @ykolomiets

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

No branches or pull requests

3 participants