Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @IBAction func createAccount(sender: AnyObject) {
- var username = usernameField.text
- var email = emailField.text
- var password = passwordField.text
- if username != "" && email != "" && password != "" {
- FIRAuth.auth()?.createUserWithEmail(email!, password: password!, completion: { (user, error) in
- databaseRef.child("users/(user.uid)/username").setValue(username)
- databaseRef.child("users/(user.uid)/password").setValue(password)
- databaseRef.child("users/(user.uid)/uid").setValue(user?.uid)
- })
- } else {
- print("please complete all fields")
- }
- }
- @IBAction func createAccount(sender: AnyObject) {
- var username = usernameField.text
- var email = emailField.text
- var password = passwordField.text
- if username != "" && email != "" && password != "" {
- FIRAuth.auth()?.createUserWithEmail(email!, password: password!, completion: { (user, error) in
- if let user = FIRAuth.auth()?.currentUser {
- databaseRef.child("users/(user.uid)/username").setValue(username)
- databaseRef.child("users/(user.uid)/password").setValue(password)
- databaseRef.child("users/(user.uid)/email").setValue(email)
- print(user.uid)
- } else {
- print("no user")
- }
- })
- } else {
- print("please complete all fields")
- }
- Auth.auth().createUser(withEmail: email, password: password) { (user, error) in
- // guard against errors and optionals
- guard error == nil else { return }
- guard let user = user else { return }
- let userObject = [
- "uid": user.uid,
- "username": username,
- "password": password, // I don't recommend storing passwords like this by the way
- "email": email
- ] as [String:Any]
- databaseRef.setValue(userObject)
- }
Add Comment
Please, Sign In to add comment