0
votes

Problem accessing the firebase reference URL directly for firebase real-time database.

Observation 1:

The project is in IoS, I have the following code in AppDeleage:

// Set up the Default DB FirebaseApp.configure()

// Set up the SecondDB FirebaseApp.configure(name: "secondDB", options: secondDBOptions)

I have no problem adding record in the DB1, using the .read != null rules. I have also set up the same rules .read != null thinking that all authenticated user will be able to access the data.

The code at one of the view controller to retrieve data from SecondDB looks something like:

guard let secondDBNews = FirebaseApp.app(name: "secondDBNews") else { assert(false, "Could not retrieve News") }

let usersDB = Database.database(app: secondDBNews).reference().child(mainDelegate.firebaseEnvironment).child("Users").child(String(Auth.auth().currentUser?.uid ?? ""))

usersDB.queryOrdered(byChild: "Email").observeSingleEvent(of: .childAdded, with: { snapshot in ... ... ...

The above seems fine, and readable when .read = true (anyone can read). However, when it is set to .read != null, the error indicates that it does not have the permission.

Observation 2:

The default one has a URL of https://DefaultDB-1234.firebaseio.com/

The second database has a URL like: https://SeconDB-1234-abc.firebaseio.com/

2 Databases - Default & Second:

2 Databases - Default & Second

For the first one, I can load the URL as such in the browser: https://defaultDB-1234.firebaseio.com/Dev/User1/Projects

DefaultDB contains data:

DefaultDB contains data

And it will display the data under the tree.

The secondDB also contains data.,

enter image description here

However, when I attempt to load the URL in the browser: eg. https://SecondDB-1234-abc.firebaseio.com/Dev/Article/Day1

Instead of loading the data from the SecondDB, it actually resolves to load the DefaultDB, and tell me that the data is NULL, even though there are data there.

Result shows null: Result shows null

Questions:

  1. Are both observations related to each other?
  2. Is there specifically any authentication configuration that I have missed?
1
How do you know that the second URL is actually accessing the first database? Are you saying you can exchange "somedatabase-1234" with "somedatabase-1234-abc" and get exactly the same results for all queries for both of them?Doug Stevenson
Hi Doug, both Database (Default, Secondary) are under the same App. I can easily referenced to any nodes under the Default url. However, for the Secondary one, programmatically I can read with Security set to .read = .true, but if I were to set it to .read != null, then it keep failing. To investigate this I tried directly accessing the URL for the secondary DB, but regardless of any nodes that I was trying to access, it resolves to the Default one. Do they have different Auth token? And if so how can I invoke them?user10513445
It sounds like you now have completely different question in your comment than you do in your original question. Can you break this down into a single question with a distinct reproduction case?Doug Stevenson

1 Answers

0
votes

it seems that the second database need to be referred directly by the url string.

So: FirebaseApp.configure(name: "secondDB", options: secondDBOptions)

Won't work.

Instead: let secondDBURL = "https://SecondDB-1234-abc.firebaseio.com"

Then

Problem accessing the firebase reference url directly for firebase realtime database.

Observation 1:

The project is in IoS, I have the following code in AppDeleage:

// Set up the Default DB FirebaseApp.configure()

// Set up the SecondDB FirebaseApp.configure(name: "secondDB", options: secondDBOptions)

I have no problem adding record in the DB1, using the .read != null rules. I have also set up the same rules .read != null thinking that all authenticated user will be able to access the data.

The code at one of the view controller to retrieve data from SecondDB looks something like:

guard let secondDBNews = FirebaseApp.app(name: "secondDBNews") else { assert(false, "Could not retrieve News") }

let usersDB = Database.database(app: secondDBURL).reference().child(mainDelegate.firebaseEnvironment).child("Users").child(String(Auth.auth().currentUser?.uid ?? ""))

Will work.