Rectangle 27 21

Yes this is possible using the Firebase console. You only get one database per project but you can have many apps per project just by adding them in the console. They don't need to have the same package name or signing key.

If you have some reason why you can't add them both to the same project, you will have to configure at least one of the apps manually in client side code. So rather than using the google-services.json file for configuration, you can call FirebaseApp.initializeApp() manually and fill in the information so both apps are talking to the same Firebase project.

Thank you so much! Though I didn't have to use FirebaseApp.initializeApp(), the information which you gave that another app can be added helped me. Thanks!

I wonder if it's a new feature of Firebase 9.0.0 to add 2 (or more?) apps under one project? Or maybe it's still against their Terms of Service and they will disable it in the future?

Yes. It's a new feature of Firebase 9.0.0.

Very helpful post, thank you! My need is the same as the person who posted: 1 app for posting data, 1 app only for fetching data.

android - Is there a way to have 1 Firebase database for 2 apps with d...

android database firebase firebase-database
Rectangle 27 4

The code in the above snippet is correct, but the address / URL of the Firebase being used is incorrect. All 'production' user Firebases use the domain firebaseIO.com, but the above code uses a firebaseIO-demo.com domain, which is security-disabled and used only for test purposes. Firebases on that domain can be created by anyone and passed around as a convenience, but cannot be authenticated to or tied to a Firebase account.

Regarding passwords in plaintext, all Firebase Simple Login requests are forced to HTTPS, so this password is never actually sent in plaintext over the wire.

Firebase simple login does not return a user object - Stack Overflow

firebase firebase-security
Rectangle 27 4

In retrieveData(), you should be using a ChildEventListener, not a ValueEventListener. You are adding Node objects as children of node/$uid with the keys generated by push(). The ValueEventListener is returning a Map<String,Object> containing all of the Nodes. That is shown in the logcat output you posted. You can use the onChildAdded() callback of ChildEventListener to get each Node as it is created and then add it to your adapter.

I am still having problems adding the collected data to the listview via the adapter. What else am I missing? I have adjusted the code to what you suggested. Check the update.

What behavior are you seeing now? Not seeing the error message any longer? Do you have a log statement in onChildAdded() to confirm that it is firing?

says it's caused by the line with the code for NodeObject nodeObject = datasnapshot.getValue(NodeObject.class);

Use the Firebase console to examine the value and nodes/$uid to confirm that it has children that are Nodes. Is there possibly some old data leftover from previous runs? If so, you can use the console to delete the extraneous values.

android - No setter/field for warning Firebase Database Retrieve Data ...

android firebase firebase-database
Rectangle 27 3

Projects that are created at firebase.google.com, can only use the Firebase Authentication SDKs available from https://firebase.google.com/docs/auth/.

You're using a Firebase 2.x SDK, specifically this createUser() method.

The fact that you're including a dependency on the new Firebase is not enough, you likely also have a dependency on Firebase for Android 2.x somewhere (e.g. compile 'com.firebase:firebase-client-android:2.5.2+'), which you'll need to remove.

If you already have an existing project on the legacy Firebase console, you can continue to use that with the 2.x SDKs. But projects that are created at firebase.google.com, can only use the Firebase Authentication SDKs available from firebase.google.com/docs/auth.

@frank-van-puffelen This error also happens on server applications using Firebase 2. The funny part is applications create using Firebase Legacy and migrated to to Google Firebase work perfectly.

android - How to solve the error "Projects created at console.firebase...

android firebase-database firebase-authentication
Rectangle 27 3

It is possible to merge accounts with the same email, even after some accounts have been created in Firebase Authentication.

First step is to disallow multiple-accounts-per-email by changing the setting in your Firebase project console. The change will only be applied to new users - all existing users will still sign into their existing accounts as before.

Since your app only uses Google/Facebook login, you can safely delete unwanted authentication accounts from the Firebase Console. Assuming in your database there is an entry (userid_1, email), and in you authentication project there are two accounts for the email (userid_1, email, Google) and (userid_2, email, Facebook). You can delete the (userid_2, email, Facebook) account using the Firebase Console or Firebase admin SDK. All subsequent logins with the same email, no matter via Google or Facebook, will always return the userid_1 account.

Firebase merge user account by email after the fact - Stack Overflow

firebase firebase-authentication
Rectangle 27 4

You can't prevent users from being created on the client using simple login. There are two options you can utilize instead:

Simple Login is just a convenience wrapper that creates Firebase tokens. There is no limit on how many accounts can be stored and they have no affect on your Firebase usage. With this in mind, there's really no reason you need to restrict creation of accounts.

Instead, just utilize security rules to control access to data. When an admin creates an account, have them also add a profile into the data. If only an admin in Forge is allowed to create the profile, then someone could create an account, but it would be superfluous and pointless, since all it does is give them an inert token.

".write": "root.child('valid_account/'+auth.uid).exists()"

A security rule that allows users to edit their profile but only Forge (admin: true) to create them:

"profiles": {
  "$uid": {
    ".write": "data.exists() && auth.uid === $uid && newData.exists()"
  }
}

If you're terribly OCD and don't like that approach, then you can cut out Simple Login. As stated previously, it just creates tokens on your behalf. So simply create your own.

In this way you have complete control over account creation and token generation.

Your rule should read: ".write": "auth != null && root.child('valid_account/'+auth.uid).exists()" otherwise, you're getting denied because it can't add the path to null (auth.uid is null if not authenticated) - but it seems like you want to do something more than deny access on an operator error. The exact error you get without checking for auth != null is: Type Error: + only operates on numbers and strings. ;)

Great point. While it helps with reading the errors in the simulator, it doesn't actually affect what users see or change the rule behavior. It's a short circuit, since user must still be authenticated for the rule to pass.

Firebase Simple Login - Prevent New Users - Stack Overflow

firebase firebase-security
Rectangle 27 4

You can't prevent users from being created on the client using simple login. There are two options you can utilize instead:

Simple Login is just a convenience wrapper that creates Firebase tokens. There is no limit on how many accounts can be stored and they have no affect on your Firebase usage. With this in mind, there's really no reason you need to restrict creation of accounts.

Instead, just utilize security rules to control access to data. When an admin creates an account, have them also add a profile into the data. If only an admin in Forge is allowed to create the profile, then someone could create an account, but it would be superfluous and pointless, since all it does is give them an inert token.

".write": "root.child('valid_account/'+auth.uid).exists()"

A security rule that allows users to edit their profile but only Forge (admin: true) to create them:

"profiles": {
  "$uid": {
    ".write": "data.exists() && auth.uid === $uid && newData.exists()"
  }
}

If you're terribly OCD and don't like that approach, then you can cut out Simple Login. As stated previously, it just creates tokens on your behalf. So simply create your own.

In this way you have complete control over account creation and token generation.

Your rule should read: ".write": "auth != null && root.child('valid_account/'+auth.uid).exists()" otherwise, you're getting denied because it can't add the path to null (auth.uid is null if not authenticated) - but it seems like you want to do something more than deny access on an operator error. The exact error you get without checking for auth != null is: Type Error: + only operates on numbers and strings. ;)

Great point. While it helps with reading the errors in the simulator, it doesn't actually affect what users see or change the rule behavior. It's a short circuit, since user must still be authenticated for the rule to pass.

Firebase Simple Login - Prevent New Users - Stack Overflow

firebase firebase-security
Rectangle 27 3

I think i can answer my question. @has9 suggestions helped me figure out that the Json database is not directly tied to an app on firebase. that is, when you create another app (app2) and delete app1, your database will not be deleted with app1. i hope i explained my answer clearly. anyways this solved my problem.

json - Firebase Transfer or Copy database from one Android app to anot...

android json firebase firebase-database
Rectangle 27 3

To be clear, let me say up front that I do NOT recommend you do this for your use case. But in general, you can allow unauthenticated users to access parts of the database by setting your security rules for that path to true:

{
   "rules": {
       ".read": true,
       ".write": true
    }
}

You would not want to do something like this because you don't want to give the public access to everyone's usernames.

Instead, I'd recommend using Cloud Functions for Firebase. You can create a Cloud Function that is triggered when a user chooses a username, perhaps by creating a temporary path in the database and using a database trigger. Now if you're not familiar with Cloud Functions or Node.js, there will be a lot of new information to learn up front, but you will discover that there are many use cases for Functions, so it's worth learning.

Thanks for the thorough response, @JenPerson! I intended including 'safe' in the question, so I'll be going with your second suggestion.

Is it possible to access Firebase data before creating a new user? (Sw...

swift firebase firebase-database firebase-authentication
Rectangle 27 3

Right now it cannot be done directly, but you could validate the user with Digits, send the security headers to a backend Web Service you developed in which you can create a email/password user using as email phone_number@yourdomain.com and as password a string you randomly created, and using firebase custom authentication to give your end users tokens to reauthenticate, all this would seem as phone authentication to the end user, and he would'n even know he is using a email/password auth to sign in

Good answer, Care to share a sample strategy, say maybe with web and node.js on the backend?

Since the firebase upgrade you cannot use the email method described above, mainly because they changed the way createUser works, but you can actually create a nodejs backend (example express js) set up the server as it is described in firebase documentation and use the digits authentication mixed with the firebase custom token to associate an UID to a phone number

Phone number based auth in Firebase (with Digits) - Stack Overflow

firebase firebase-authentication twitter-digits
Rectangle 27 1

Unfortunately, you can't add extra fields to FirebaseUser. You have to use "real-time database". You can create a database node called "users" and save there your user-specific fields (use FirebaseUser UID as the key for the database). Then when the user login in your app you can get their info from the database.

To explain in details: you have to use firebase authentication to login and register users, after that (for example on register completion) you save user's information in the real-time database node. Then after login (with firebase authentication) you will use user's uid to get all the user's details from the real-time database. You need this also if your users can view other user's profile... you can't get another user information from the "authentication table".

Thanks @Utnapishtim I will look into the separate Users table but how do I register a user who will authenticate themselves via Google, Facebook, Twitter with this table? I can't seem to find an example of this.

No, you have to use firebase authentication to register and login users. You have to use the real-time database to store other information that firebase doesn't save in the "authentication". I will edit the answer.

Firebase app user registration using google - Stack Overflow

firebase firebase-authentication
Rectangle 27 1

Unfortunately, you can't add extra fields to FirebaseUser. You have to use "real-time database". You can create a database node called "users" and save there your user-specific fields (use FirebaseUser UID as the key for the database). Then when the user login in your app you can get their info from the database.

To explain in details: you have to use firebase authentication to login and register users, after that (for example on register completion) you save user's information in the real-time database node. Then after login (with firebase authentication) you will use user's uid to get all the user's details from the real-time database. You need this also if your users can view other user's profile... you can't get another user information from the "authentication table".

Thanks @Utnapishtim I will look into the separate Users table but how do I register a user who will authenticate themselves via Google, Facebook, Twitter with this table? I can't seem to find an example of this.

No, you have to use firebase authentication to register and login users. You have to use the real-time database to store other information that firebase doesn't save in the "authentication". I will edit the answer.

Firebase app user registration using google - Stack Overflow

firebase firebase-authentication
Rectangle 27 0

[Disclosure: I work for Firebase] We do root for you reaching that number of course. :-)

Firebase - How many databases can be created? - Stack Overflow

firebase
Rectangle 27 0

Firebase will load the data from the server only once. After that your JavaScript code can construct as many refs on it as you need, without downloading the data again.

But post.comments.$asArray() will not work, since your post is a plain JavaScript object (and not a $firebase sync anymore).

var ref = new Firebase(FIREBASE_URL + "/posts/" + post_name);
var post = $firebase(ref).$asObject();
var comments = $firebase(ref.child("comments")).$asArray();

But you may want to reconsider your data structure. Even though Firebase is a hierarchical data store, they recommend against building deeply nested hierarchies. See Avoid Building Nests on https://www.firebase.com/docs/web/guide/structuring-data.html

Because we can nest data up to 32 levels deep, it's tempting to think that this should be the default structure. However, when we fetch data for a node in Firebase, we also retrieve all of its child nodes. Therefore, in practice, it's best to keep things as flat as possible, just as one would structure SQL tables.

So in your case that could lead to having two top-level elements posts and comments.

root
  posts
    post1
    post2
  comments
    post1
      post1comment1
      post1comment2

And you can then simply load the post and its comments with:

var root= new Firebase(FIREBASE_URL);
var post = $firebase(root.child("posts").child(post_name)).$asObject();
var comments = $firebase(root.child("comments").child(post_name)).$asArray();

firebase - AngularFire Accessing child element methods - Stack Overflo...

firebase angularfire
Rectangle 27 0

Have you followed the Firebase FCM properly? The FCM token is triggered when FCM token is not created yet in users phone. If existed, the push notification will not be a problem if the app is not open. You can called onTokenRefresh() to init the FCM token.

android - Firebase Cloud Messaging works only after first start of the...

android firebase firebase-cloud-messaging
Rectangle 27 0

There are many ways to send notifications. One such is via firebase console. If you want to send notification through other applications then it can be using Postman. Here you can refer this method by this you can send notification to particular device and for the topics too.

android - Shall i use FIREBASE CONSOLE to send push notification to al...

android firebase push-notification firebase-cloud-messaging
Rectangle 27 0

Developers can use Cloud Functions to keep users engaged and up to date with relevant information about an app. Consider, for example, an app that allows users to follow one another's activities in the app. In such an app, a function triggered by Realtime Database writes to store new followers could create Firebase Cloud Messaging (FCM) notifications to let the appropriate users know that they have gained new followers.

Here is a demo project for sending device-to-device push notifications with Firebase and Google Cloud Functions.

How to send device to device messages using Firebase Cloud Messaging? ...

firebase firebase-cloud-messaging
Rectangle 27 0

Developers can use Cloud Functions to keep users engaged and up to date with relevant information about an app. Consider, for example, an app that allows users to follow one another's activities in the app. In such an app, a function triggered by Realtime Database writes to store new followers could create Firebase Cloud Messaging (FCM) notifications to let the appropriate users know that they have gained new followers.

Here is a demo project for sending device-to-device push notifications with Firebase and Google Cloud Functions.

How to send device to device messages using Firebase Cloud Messaging? ...

firebase firebase-cloud-messaging
Rectangle 27 0

In a typical database schema each Channel / ChatGroup has its own node with unique $key (created by Firebase). It shouldn't matter which user opened the channel first but once the node (& corresponding $key) is created, you can just use that as channel id.

Hashing / MD5 strategy of course is other way to do it but then you also have to store that "route" info as well as $key on the same node - which is duplication IMO (unless Im missing something).

I think they are doing it to preserve the information which user started the chat.

Thats true though to create the hash you sort user-names so in the end you really dont know who started that channel. If you really need this information you can just create property under your chat-channel-node. Typically if the channel has multiple users you should make someone "admin" of that channel & give few special "powers" but yeah depends on your application's needs.

javascript - Best way to manage Chat channels in Firebase - Stack Over...

javascript arrays firebase chat
Rectangle 27 0

If Firebase is online at the start and loses its connection temporarily, then reconnects later, it will sync the local data then. So in many cases, once Firebase is online, you can simply keep pushing to Firebase during an outage.

For true offline usage, you will probably want to monitor the device's state, and also watch .info/connected to know when Firebase connects.

new Firebase('URL/.info/connected').on('value', function(ss) {
   if( ss.val() === null ) /* firebase disconnected */
   else /* firebase reconnected */
});

The way to achieve this with the current Firebase toolset, until it supports true offline storage, would

  • keep the local data simple and small
  • when the device comes online, convert the locally stored data to JSON
  • use set() to save the data into Firebase at the appropriate path

Additionally, if the app loads while the device is offline, for some reason, you can "prime" Firebase by calling set() to "initialize" the data. Then you can use Firebase as normal (just as if it were online) until it comes online at some point in the future (you would also want to store your local copy to handle the case where it never does).

Obviously, the simpler the better. Concurrent modifications, limits of local storage size, and many other factors will quickly accumulate to make any offline storage solution complex and time consuming.

Thanks for the tips, i'll quickly try to implement this. Next thing to do would be to be able to start offline...

Hi, I dont understando what do you mean with ... you can "prime" Firebase by ...Thx

Any solutions to dealing with Firebase authentication? Caching the tokens locally and allowing login without hanging the application?

The latest version of Firebase provides some improved support for auth in offline modes. Read about it in the docs. However, full offline support won't be possible until offline persistence is available.

What happens when the data is off time wise? If I set() or update() and it reconnects wont it consider that data as newer and overwrite the server?

angularjs - How to sync offline database with Firebase when device is ...

angularjs cordova firebase