Web Push Same Subscriber Different Endpoint Issue - javascript

I am trying to implement the web-push service in one of my projects. So, I actually need to know the actual subscriber numbers in my app. So what problem I am facing is, the service worker generates new endpoints for the same user and I didn't find any unique thing by which I can figure out if the subscriber exists or not.
All my users are also guest users so I don't have any unique thing. There is also an event called onPushSubscriptionChange which doesn't also work in other browsers except for Mozilla.
So is there any way to uniquely identify a user? Like if multiple endpoints are created for the same user then I want to replace the old endpoint with the new one in my database. I am not willing to use cookies also.
Another thing is does firebase cloud messaging solves this issue?
Thank you

Related

Electron. Autoupdating app when it notices the change in the database or selected server?

My client wants applications written in electron which works both offline and online. The application is to connect to the server / database and download data (photos and descriptions of products) so that it can work in the offline version. When it is online, the application checks whether there is any change on the server / database and then an update occurs.
I have already prepared such applications (search engine and product filters with the possibility of generating pdf), but I have no idea how the application would check whether the server existed any of the data and download new photos of products, etc.
Yeah well the question is: Do you want to run you're queries on the Client it self? Because then, if not strictly restricted, someone finds a way to open up the console and sends funny queries.
But anyway... your question:
The easiest way I can think of this, because we don't want to download everything again, is to have a version number for each element.
So the client has one and if that does not match the servers it gets updated. Now you just have to get all IDs. But keep in mid, you still have to handle what happens if an item gets removed or a new one added.
This is not really an answer but I hope it inspired you a little bit.
Oh some after thoughts:
You could get something like a WebSocket between those two. Yes you had to program one more service but
The query would be save
You could keep track of removed and added items
You could work out some timestamp system that you get all items that are newer than the timestamp of the client.. this will be some work though.
nice day, Elias

Javascript creating hubs?

I have an express server setup that is handling all of my routing and session stuff. I want the system to work so that when a user is logged in they are able to connect to a "hub" like entity that is uniquely based on the location of the "hub". I thought about working it like each of the "hubs" is a collection in a database, but the way it works is that a user connects to the "hub" and then disconnects from it when they are done but can connect to different "hubs" based on a location. How should I go about creating a unique group of "hub" like things that all act as objects with storable data?
Instead of connecting to a "hub", why not just present them with different information from a database based on their location. The user will never really connect to anything other than your single backend. Unless, ofcourse, you set up different servers all over the world (known as a CDN, and probably a bit too much effort).
If you're using express, you could use something like mongodb for data storage.
With mongodb you get the mongoose npm package. With that, you can create Schemas. You could have different Schemas as "hubs" and load the correct ones based on location data. That would let the user see different information for different locations.

Using MongoDB to separate different user data

I'm already familiar that MongoDB is based on documents that are in JSON format. I'm creating my first web app using the MEAN stack, where users can register and then be able to sign in to a back-end dashboard where they can implement products/profile information etc. How would I set that up to be stored on MongoDB? would each user be stored as a document? And as far as security reasons, how can I go about not allowing a GET request to be able to get a different users information?
Currently, I just have a collection of users, and a collection of products (with the unique id number for each user), etc. to me that doesn't seem the proper way to store data.
If anyone can help me on how to setup the database for Mongo that would be fantastic! Thanks in advance!
would each user be stored as a document?
Yes, each user is an object, thus it's stored as a separate document.
how can I go about not allowing a GET request to be able to get a different users information?
This has nothing to do with Mongo or any other data storage mechanism. You'll need to work on a Web service layer which exposes your data filtering requests to authorize them based on user role, claims or any authorization approach you might find useful in your scenario.
Maybe you should look at implementing OAuth2. There's a package that integrates with Express to implement your own OAuth2 authorization server: node-oauth2-server.
Currently, I just have a collection of users, and a collection of
products (with the unique id number for each user), etc. to me that
doesn't seem the proper way to store data.
You are on the right way actually. Now when you show products page for users you need to retrieve only documents that belong to that single user that is currently authenticated, this implies that you have authentication set up, and products have a userId field.
This is how most application work. If you want to read about other ways of solving this then read about multi-tenancy.

How to configure Autobahn(crossbar.io) for dynamic chat rooms?

I love crossbar.io and how it works(personally). But I would like to know how we could setup the architecture for a typical dynamic chat application using Autobahn(Crossbar.io).
Dynamic chat here means, individual chat room created for each url.
For example: http://www.myapplication.com/chat?roomId=123 , creates a chat room subscribing to topic "com.myapp.chat123".
http://www.myapplication.com/chat?roomId=456 , creates a chat room subscribing to topic "com.myapp.chat456".
We need to store the chat messages in the Database for future reference, since Autobahn doesn't have message persistence.
Now my questions are:
If each chat room use separate topic, then how we could subscribe for the messages in the server(since we can't subscribe using Patterns as of now) ?
Since we will use separate topic for each room, how we do authentication and authorization in Crossbar.io ?
I couldn't able to find the Javascript documentation for setting the features as mentioned here. Where to find it ?
In this SO answer, it was mentioned that crossbar.io provides meta-events for session join or leave on Router. Is there any way to know when user subscribes or unsubscribes to specific topic instead of Router join or leave ?
Could you explain how to configure available advanced profile features with Current version of Crossbar.io (in Javascript, browser or Node.js) ?
Could you explain about Event History feature in detail ? And how to configure it ?
I'll answer your question one by one:
At least, it's your client which wants to subscribe to his topic (correct me if I misunderstand), then, you need to store a list of topic ID related to user in your database, and when your client connects to the server, you send him the list of topic ID and let him subscribe all of them.
Authentication / Authorization process has nothing to do with a separate topic. You can do something like that:
There is two way to authenticate, anonymously and WAMP-CRA. Then, you assign a role for anonymously connected clients, and another role for authenticated client (this role can be different following the database e.g: user, admin, moderator, ...)
When authenticated, subscribing to a topic needs authorization (implemented by a dynamic authorizer, you can see how to do it there: https://github.com/tavendo/AutobahnPython/blob/master/examples/twisted/wamp/authorization/router.py -- basically, it is the same, except you forget the router thing and you focus on the authorize method)
Then, you authorize based on something like Access Control.
Unfortunately, the doc is quite outdated, you should ask for it on the Mailing List which features you want to use and how can you use them.
As I recall, there is a meta-event on_subscribe/on_unsubscribe.
Advanced features can be configured in the config file of Crossbar, they can be also an argument passed to publish/subscribe/call/register calls.
I'm not a core developer of Autobahn, but as much as I understood, it is a feature that give you a way to get all previous published data from a topic (X last ones, since a TIMESTAMP, after a ID).
I know that Autobahn is hard to follow sometimes due to the documentation, but examples can help a lot, and here there are a lot of interesting things: https://github.com/crossbario/crossbarexamples (including Authentication, MetaAPI, Patterns).
I hope that I've answered most of your questions, but yet, if there are things you don't understand, I recommend you to go to the mailing list, this is your best try, in my opinion.

Add data to Parse.com class by sending email

I'm working on a website where there's a requirement for pretty constant updates, adding names to a list of backers. Naturally, as a developer who has other work, I don't want to be responsible for updating it all the time.
Since we're using Angular, there's no frontend web portal, so I thought of Parse.com as an easy way for the client to log in and add names as entries under the correct class. Works fine. But the client finds it too hard to use, so I'm looking for another solution. A thought I had was email, so I'm going for it.
How can I add a new entry in a Parse DB in response to an email sent to a specific address?
Thanks!
Oops. Didn't do enough Googling. Easiest way to do it seems to set up an account at Mailgun and set up a Route to forward certain data to a cloud function in Parse. Who knew. More details.

Categories