Is it possible to push web notification in Firebase for anonymous users with using just the UID because there will be no tokens for anonymous authentication.
The firebase authentication UID are not related to the tokens you get from the WebPush subscription.
That means you can subscribe any kind of user with webpush as described here, and don't even think about firebase authentication.
Related
I am currently using firebase to make an ionic app. I am using firebase simple login for social auth (facebook, twitter, email & password). The auth works perfectly, it $broadcasts the authed user. However it doesn't seem to create a user in the actual firebase db. I was wondering how I can get the users that have been authed using my app.
For most of the authentication protocols it supports, Firebase doesn't store user data anywhere. Even for the protocols where it does store data (I only know of email+password doing this), it stores this information in a place that your application can't access (though you can find those users in the dashboard of your Firebase).
To quote the Firebase documentation:
It does not store profile or user state in your Firebase. To persist user data you must save it to your Firebase.
What most applications end up doing, is keeping a list of users inside their Firebase that they manage themselves. So when a user first authenticates with the application, it creates a node under /users/<uid> that contains the information for that user.
See this section of the Firebase documentation that describes storing user data.
Firebase does not store profile or user state in your Firebase instance. To persist user data you must save it to your Firebase.
Firebase provides multiple authentications services
Using existing social login providers such Facebook, Twitter, Google, and GitHub. Using these services provides an option for your users to access your application without creating a new account.
Using built-in support for logging in with email & password. This requires registration and account creation that is handled by Firebase. The user account information is stored outside you application.
Using a custom authentication to implement existing server-side authentication, single sign-on, legacy systems, or third-party OAuth based services (such as Yahoo).
Once authenticated, Firebase return a variable auth to your application that you can use for authorization and access control. This variable is null for unauthenticated users, but for authenticated users it is an object containing the user's unique (auth.uid) and potentially other data about the user.
If you want to persist additional user information such as name
and location, then you need to use auth.uid and store it in your
Firebase with additional profile data.
Internally, Firebase generates JSON Web Tokens (JWTs) and creates authenticated sessions by calling Firebase.loginWithCustomToken() with those tokens. Each user is assigned a uid (a unique ID), which is guaranteed to be distinct across all providers, and to never change for a specific authenticated user.
The user data for firebase authentication is stored in firebaseLocalStorageDb in IndexedDB. After login to website, if you delete firebaseLocalStorageDb, the login user data for firebase authentication is all deleted so you need to log in website again.
Im trying to use firebase cloud messaging to enable push notifications on my PWA.
but i can't figure out how to save tokens after the 'user' click on 'accept' on the push notification subscription message.
Should i save token to a firebase database? or there is a automatic system to subscribe/unsubscribe/ clean the list of tokens.
Did you mean registration tokens? If so, please check out this doc which has comprehensive information about how to manage registration tokens.
When I generate an FCM token in the browser I also send it to my server, which subscribes it to a topic with the firebase admin module like so:
messaging.subscribeToTopic(token, 'all')
I'm wondering if I delete the token in the browser using the messaging.deleteToken(currentToken) method do I also need to unsubscribe that same token using messaging.unsubscribeFromTopic(token, 'all'); on my server or does firebase do that automatically when the token is delete?
A topic subscription is really just a simple way to subscribe many ID tokens to a string. On the FCM fan-out servers that is pretty much exactly what is stored: a list of tokens associated with each topic.
Deleting a token will not really unsubscribe the token from the topic. But since the token is the only way that FCM can deliver messages to a device, messages sent to any topics the token was subscribed to can no longer be delivered (and will be cleaned up behind the scenes automatically).
I have an android app that uses firebase to handle and send push notifications. When an user logs-in, it is automatically subscribed to a topic in firebase and saved the token in my database.
If after logging into the app, the users uninstall the app, their token is still in firebase, subscribed to the topic. If firebase call sendToTopic("topic"), probably will fails due this invalid token.
There is any way to get notified about those invalid tokens? I need those tokens to unsubscribe it from the topic and remove it from my database.
My end goal here is to subscribe web clients to topics in Firebase Cloud Messaging to receive simple data push events, partitioned by keys. Via this question, that seems to be possible, but only if you can send the clients' registration keys to an app server you control using the FCM Admin API: How to subscribe to topics with web browser using Firebase Cloud Messaging
Also, via https://firebase.google.com/docs/cloud-messaging/js/client, it seems to be required to request permission from the user to show desktop notifications in order to get access to the registration token for Firebase messaging.
Is there any way to tell Firebase no, I absolutely do not want desktop notifications, in fact please never show them, I just want to use data messages and never notification? And then, to get the registration token? Alternatively, is there some other way to subscribe to topics from a web client?
There is currently no other alternative to get a registration token nor is there a different way to subscribe to topics for a web client.
You already know this, but might as well mention it. Requesting permissions is a must for security purposes (preventing notifications not wanted by the user) and that in order to subscribe a web client to a topic, you'll first have to get a token (which won't generate unless the user grants permission).
Looks like you are looking for Pusher
User channel for communication. Works with out token and support bidirectional contact.
Sample code
Back End
pusher->trigger('my-channel', 'my-event', [
'message' => 'hello world'
]);
Front End
var channel = pusher.subscribe('my-channel');
channel.bind('my-event', function(data) {
alert('Received my-event with message: ' + data.message);
});