Raix/push: Get user token on server side method


After figuring out how to get the user push token on client side, I was wondering how to get same on server side during a method call.

Thanks in advance! :slight_smile:


Push.appCollection.find({ userId: … }).fetch();


I am sorry, I should have been clearer.
The users don’t have to register in order to use the app, so I save the tokens in a database for every push notification the user enables.
For security reasons I want to get the token from the server side instead of letting it get submitted by the user call.


If user is not registered, how you decide what token to use to send push notification?
And tokens are generated for device, so you need to get it from user.


Well, I created a “help database” where every token gets stored in.
So if a user enables push for a certain “category”, it will insert the user’s token and the category in the database.
When there is a push notification for this category, it will search through the database and send to all tokens associated with that category.
It’s simply no option for me to let everybody register itself with the app just to get a push notification.
And this works perfectly fine - I just thought there was a way to get the token with “this.token” or something during a “Meteor.call” from the server side.
I guess, there is no way (yet) to do so.


I recommend you not to use raix:push, but apn and node-gcm npm packages. Because your situation with sending push to unregistered users requires too much customisation in case of using raix:push.
Tokens are generated only on device (not generated, but requested from google/apple), and then you can store them in your db. But don’t forget to remove “dead” tokens.


Good point!
I was thinking about the “dead” tokens too and could not come up with a method to remove them yet.
So I will take a look at the npm packages and see what they offer.

Does raix:push support feedback?

Thank you for your help! :slight_smile:


If you will manage tokens by yourself, then you can remove them when you get response from apn/gcm about “no such device” or similar. You can get response codes in google/apple developers documentation.

“Does raix:push support feedback?” - what kind of feedback?


With feedback I meant the response that the device could not be reached or something similar.
So that if I send a push notification via raix:push I could directly remove the token if the delivery failed.


Yes, raix:push is doing this for you. But when you use npm modules you can analyse server response and remove tokens by yourself.