Brinox
Brinox

Reputation: 37

Create a database entry for the UID after sign up with firebase and swift

I’m developing an app in swift by using firebase in the back end.

I have successfully created a user by using the standard procedure as stated in the documentation.

My problem comes when I want to add the UID value to the database. I can’t. What I’m doing is getting the UID (userID) from the Auth().user (what I successfully do) and using the following code (I don’t have de computer do it can contain errors but I copy it from the documentation and I’m fact it compiles, the problem is that is does nothing

let ref = Database().database().reference()
self.ref.child(“users”).setValue(userID)

I have tried with the following

Self.ref.child(“users”).child(user.id).setValue(userID)

But it fails due to the fact that users have no children. The issue is that users is a collection and I don’t now if it works in the same way or not.

My intentions is to create the entry in the “users” collection in the database just after singing up a new user. (And to be able to layer erase it)

Thanks!

Upvotes: 0

Views: 438

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598728

Firebase has two NoSQL databases:

  1. the Realtime Database, which is the original JSON database.
  2. Cloud Firestore, which is the newer document/collection database.

These two databases are both part of Firebase, but have completely separate APIs.

You speak about collections in your question, which are a Cloud Firestore concept. But your code uses the API of the Realtime Database. If you're looking to write data to Cloud Firestore, you'll want to use the API that is documented here.

Upvotes: 2

Related Questions