Parameters to the Firebase Push Messaging System - firebase

I am using Firebase Push notification its works fine but i have a question what if,
I need the ability to provide parameters to the Firebase push
messaging system that will allow me to display a message that, when
clicked, goes to a specified web link - in a web view. Most
importantly, this needs to function when the user does not have the
app loaded.
Is it possible ?? I gone through the documentation of firebase but didn't get anything about it.

For sending notifications to a user when they might not have the app running, use Firebase Cloud Messaging.
For sending messages to a user when they might not have the app installed, use Firebase Dynamic Links or Invites.

May be you have to try "Advance options" under the pushnotification by sending the key value pair like following(link is parameter and you set this parameter value in firebase console):
window.FirebasePlugin.onNotificationOpen ((notification) {
if notification.link != '' && notification.tap == true
ref = cordova.InAppBrowser.open(notification.link, '_blank', 'location=yes')
window.open = cordova.InAppBrowser.open
}

Related

Open Flutter app based on notification data?

How can I open the flutter app based on notification data using FirebaseMessaging?
So, when I tap on a notification (received through Firebase Messaging), the message handler should evaluate the data and based on them open the app. At the moment it is asynchronous, meaning the app starts and the notification handler continues the work.
It is important to know, that Navigator.push can't be used, as there is an important app setup screen, which checks the auth state and so on at app start. How to solve this issue?
When you tap a notification from the device's notification centre the operating system will launch the app, provided of course you have set up Firebase messaging correctly as per instructions the onLaunch or onMessage functions will get called.
Now since firebase messaging configured pretty much as early as possible, typically inside the main entry of the flutter app you will need to store the notification somewhere first. This can be a global state object created before anything that uses it.
final notifications = <NotificationData>[]; // globally accessible (i.e. via Provider)
Then in the handler of the messages...
NotificationData onMessage(Map<String, dynamic> data) {
notifications.add(NotificationData.fromJson(data));
}
The flutter app will start and the MaterialApp will get built. At this point you can have a loading screen to check if the user is authenticated or any new messages in the notifications global state. If there are you can route to a page to display the notification, or get the user to sign in then route to the notification page.

Fake users in firebase with #gmail.com accounts

I have a firebase project.
The next sign-in methods auth are enabled:
Google
Facebook
Apple
Anonymous
A mobile app interacts with the firebase.
Each day I get some weird new users sign-ups with fake accounts with the pattern: [name][numbers]#gmail.com. They don't do anything except sign up via google oauth once.
Is it possible to prevent it? Maybe I missed something with the google oauth configuration?
Updated:
Also, I noticed that these sign-ups started to occur when I had sent out the mobile app to google/apple verification. May these two events are correlated?
New accounts created coz of Play market Pre Launch Report
You can change Pre Launch Report settings to change it's behaviour (e.g. specify test account to use in auth)
If you are sure those fake users have a specific pattern from their email address, I would make a trigger function on Cloud Functions for Firebase.
You can use functions.auth.user().onCreate() event handler like below.
exports.checkFakeUser = functions.auth.user().onCreate((user) => {
// You can check if the user has suspicious email patterns and delete them here.
});
Or you can also make a Schedule function on Cloud Functions for Firebase and daily check if there are fake users and automatically delete them.
Plus, it would be a good step if you figure out that fake users still joining even you didn't expose your mobile app anywhere if you want to find out the reason how they are joining.
Add the following Cloud Function will help you on check the email and delete the fake user
exports.checkFakeUser = functions.auth.user().onCreate((user) => {
const list = user.email.split(".")[1].split("#")
const isFake = list[0].length === 5 && list[1] === 'gmail'
if(isFake){
admin.auth().deleteUser(user.uid)
.catch(function(error) {
console.log('Error deleting user:', error);
});
}
});
You can't stop specific accounts from being created, as the underlying Google Auth APIs are accessible to anyone with an account. You could manually delete them, or write a program to delete them (bearing in mind that you could also be deleting actual user accounts).
Or if you suspect abusive behavior, you can contact Firebase support to report that.
Check, these e-mail addresses will be re-logged when they upload a new version to google play. The most likely reason for this is that google keeps your application to a number of tests with its automation infrastructure.

How to Connect Google Play Real-Time Developer Notifications to Firebase Cloud Function via Pub/Sub?

I'm in the final stages of development for my new mobile app, but can't seem to find a way to allow Google Play Real-Time Developer Notifications to communicate to a firebase cloud function via the recommended Google Pub/Sub method.
The expected payload flow should go as follows:
User Purchases Subscription via Play Store > Play Store sends R-T Dev Notification to Pub/Sub > Pub/Sub sends message across to firebase cloud function > Cloud function runs with payload.
I currently have an Apple Developer webhook set-up in a similar way, which webhooks a receipt payload to an iOS cloud function I have setup.
During the pub/sub setup phase, the Pub/Sub page asks to verify the cloud function URL, which I cannot do as I am not the true webmaster of cloud function domain, hence halting me about halfway down the 'Add real-time developer notification' docs that google supplies.
Is there a way to get the RT notification to either a Pub/Sub cloud function or a HTTPS cloud function bypassing the google Pub/Sub and going directly to the webhook or another way to complete the flow above?
The ultimate aim is to provide a way to ensure the purchase made is actually a valid purchase, and not a forged request made by someone intercepting the client > server webhook and submitting one of their own accord.
After creating the new topic you DO NOT have to create manually a Pub/Sub subscription as explained in the documentation.
To make it work with firebase you have to deploy a new cloud function like this:
exports.YOUR_FUNCTION_NAME = functions.pubsub.topic('YOUR_TOPIC_NAME').onPublish((message) => {
// Decode the PubSub Message body.
const messageBody = message.data ? Buffer.from(message.data, 'base64').toString() : null;
// Print the message in the logs.
console.log(`Hello ${messageBody || 'World'}!`);
return null;
});
Please note that you need to replace YOUR_FUNCTION_NAME and YOUR_TOPIC_NAME.
When the deploy of this function finish, you will finally find the function in the subscription list.
At this point, you can edit the params of the automatically created subscription, and you will find the url endpoint already filled with an internal url.
Here you can find an example: how to setup a PubSub triggered Cloud Function using the Firebase SDK for Cloud Functions.

Enabling the notification feature for my firebase app

I have made an app with the use of firebase. It is basically a chat application in which you van send and receive the text and images. I want to add a functionality in it that whenever a user sends a msg, then another user should get a notification . When I try to send a notification through the firebase console, then it is working, but when a user messages through the app, then it is not showing any notification to another user. So, can anyone tell me that how can this functionality be achieved ?Also, provide some sample code to see how things are working
You need to use cloud functions for that:
https://firebase.google.com/docs/functions
Cloud Functions for Firebase lets you automatically run backend code in response to events triggered by Firebase features and HTTPS requests
First, you can register the user to a topic:
FirebaseMessaging.getInstance().subscribeToTopic("news");
https://firebase.google.com/docs/cloud-messaging/android/topic-messaging
Then when the message is sent to the database, you can use onWrite() in cloud functions which is a database trigger to be able to send the notification.
https://firebase.google.com/docs/functions/database-events

Permanent Notification From Firebase Cloud Function?

Is it possible to send permanent notification from firebase cloud functions? User can't dismiss that notification?
For iOS you cannot, but Android you could setup a local notification using remote config.
iOS Remote Notifications
While you could send the same notification over and over again, control of the notifications is at the OS level of the client device. iOS would never let you create a local or remote notification that cannot be dismissed because it would be a poor user experience. In addition, I think you would find that your users would not be happy about it as well.
An alternative, would be to create a custom UI Header in your app that includes a label. You could then use Firebase Remote Config to set a value for that label, that way you can deliver the same message to all users of your app.
Android Push Notifications
In Android, it looks like you can have permanent notifications. However, it looks like this is controlled at the client level. So I still recommend the remote config option here as well. Set the value of the remote config, and then generate a local notification and set the notification to not clear.
notification.flags |= Notification.FLAG_NO_CLEAR;
Perhaps, a key/value pair could be sent from your Firebase Cloud Message call, but you will run into other issues as well. When should the function be called? Will you generate a new notification for every new user added to Firebase? This could become more expensive versus the remote config route.
Google Chrome Notifications
The remote config option should scale to this as well. A quick Google search didn't show anything that would suggest you can do a permanent notification like Android. And even if you could then your solution wouldn't work in Safari and other browsers.

Resources