My goal is to link two users together via the unique UID of the first user (in other words User B belongs to User A).
I took the following steps:
- I registered a new user (A) with email and password authentification.
- I logged-in with this user (A). This user represents the role "superuser".
- I create a new user (B) while user (A) is loggedin. User (B) represents the role "simpleuser".
I want to store the User information (UID, Email, Password) of the new user (B) together with the UID of the loggedin user (A), so that the result in Firebase looks something like this:
root -superusers -Bl41OxkohiNFc3 -email: superuser@example.de -password: test -simpleusers -Vl21OxkohiFFc3HQ -superuserUID: Bl41OxkohiNFc3 -email: @example.de -password: test
Im having problems with step Nr.4. Xcode/Firebase won't save the UID of user A, it always saves the UID of user B in superuserUID.
Here is my code for Step4:
@IBAction func RegisterSimpleUser(_ sender: Any) {
FIRAuth.auth()?.createUser(withEmail: autoemail, password: autopassword, completion: {(user, error) in
if error != nil {
print(error!.localizedDescription)
} else {
print ("User created")
}
let userID: String = user!.uid
let userEmail: String = simepleuser_email
let userPassword: String = simpleuser_password
let SuperUserID: String = (FIRAuth.auth()?.currentUser?.uid)!
//simepleuser_email, simpleuser_password coming from Text Fiels
ref.child("simpleusers").child(userID).setValue(["SuperUserID": SuperUserID, "Email": userEmail, "Password": userPassword])
}
What am I doing wrong? Can anybody help me or point me in the right direction? I'm new to Firebase/Swift. Thanks.