I am building an app that uses Firebase's email and password login feature. I am having the user register with a username, email, and password. I am struggling with how to stop the user from being created if the username is not unique. I have been reading other questions (specifically Firebase-android-make-username-unique and how-prevent-username-from-duplicate-signup-infirebase) but I have still not gotten it to fully work.
I followed the instructions in the first link above and set up my data structure as:
app : {
users: {
"some-user-uid": {
email: "test#test.com"
username: "myname"
}
},
usernames: {
"myname": "some-user-uid"
}
}
and my security rules as:
"users": {
"$uid": {
".write": "auth !== null && auth.uid === $uid",
".read": "auth !== null && auth.provider === 'password'",
"username": {
".validate": "
!root.child('usernames').child(newData.val()).exists() ||
root.child('usernames').child(newData.val()).val() == $uid"
}
}
}
With this setup, if I try to create a new user with a username that already exists, it stops the user from being added to my data structure. When the below code is called, it prints "User Data could not be saved" if the username is a duplicate.
func createNewAccount(uid: String, user: Dictionary<String, String>) {
USER_REF.childByAppendingPath(uid).setValue(user, withCompletionBlock: {
(error:NSError?, ref:Firebase!) in
if (error != nil) {
print("User Data could not be saved.")
} else {
print("User Data saved successfully!")
}
})
}
func addUsernameToUsernamePath (userData: Dictionary<String, String>) {
USERNAME_REF.updateChildValues(userData)
}
Here is where I am stuck. My create account method below doesn't call the above two methods until createUser and authUser are called (Which I need to get the uid). My problem is the user still gets created as a registered user and my security rules just keep the users information from being added to my data structure. I need to figure out how to stop the user from being created if there is a duplicate username.
#IBAction func createAccount() {
let username = usernameField.text
let email = emailField.text
let password = passwordField.text
if username != "" && email != "" && password != "" {
// Set Email and Password for the New User.
DataService.dataService.BASE_REF.createUser(email, password: password, withValueCompletionBlock: { error, result in
if error != nil {
print("Error: \(error)")
if let errorCode = FAuthenticationError(rawValue: error.code) {
switch (errorCode) {
case .EmailTaken:
self.signupErrorAlert("Email In Use", message: "An account has already been created for this email address.")
default:
self.signupErrorAlert("Oops!", message: "Having some trouble creating your account. Please try again or check your internet connection.")
}
}
} else {
DataService.dataService.BASE_REF.authUser(email, password: password, withCompletionBlock: {
err, authData in
let user = ["provider": authData.provider!, "email": email!, "username": username!]
let userData = [username!: authData.uid!]
DataService.dataService.createNewAccount(authData.uid, user: user)
DataService.dataService.addUsernameToUsernamePath(userData)
})
EDIT
Here is my updated createAccount method that solved my issue.
#IBAction func createAccount() {
let username = usernameField.text
let email = emailField.text
let password = passwordField.text
if username != "" && email != "" && password != "" {
DataService.dataService.USERNAME_REF.observeEventType(.Value, withBlock: { snapshot in
var usernamesMatched = false
if snapshot.value is NSNull {
usernamesMatched = false
} else {
let usernameDictionary = snapshot.value
let usernameArray = Array(usernameDictionary.allKeys as! [String])
for storedUserName in usernameArray {
if storedUserName == self.usernameField.text! {
usernamesMatched = true
self.signupErrorAlert("Username Already Taken", message: "Please try a different username")
}
}
}
if !usernamesMatched {
// Set Email and Password for the New User.
DataService.dataService.BASE_REF.createUser(email, password: password, withValueCompletionBlock: { error, result in
if error != nil {
print("Error: \(error)")
if let errorCode = FAuthenticationError(rawValue: error.code) {
switch (errorCode) {
case .EmailTaken:
self.signupErrorAlert("Email In Use", message: "An account has already been created for this email address.")
default:
self.signupErrorAlert("Oops!", message: "Having some trouble creating your account. Please try again or check your internet connection.")
}
}
} else {
// Create and Login the New User with authUser
DataService.dataService.BASE_REF.authUser(email, password: password, withCompletionBlock: {
err, authData in
let user = ["provider": authData.provider!, "email": email!, "username": username!]
let userData = [username!: authData.uid!]
// Seal the deal in DataService.swift.
DataService.dataService.createNewAccount(authData.uid, user: user)
DataService.dataService.addUsernameToUsernamePath(userData)
})
You could allow sign up without a valid username, and have a separate "set username" screen that you show in the event of a partial registration.
Define your security rules to check for a non-null username before allowing writes to other parts of your database.
I was able to get it working by updating createAccount() to the code below.
#IBAction func createAccount() {
let username = usernameField.text
let email = emailField.text
let password = passwordField.text
if username != "" && email != "" && password != "" {
// Checks for internet connection before saving the meetup. Returns if there is no internet connection.
let reachability = try! Reachability.reachabilityForInternetConnection()
if reachability.currentReachabilityStatus == .NotReachable {
let internetAlert = UIAlertController(title: "No Internet Connection", message: "Please make sure your device is connected to the internet.", preferredStyle: .Alert)
let internetAlertAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
internetAlert.addAction(internetAlertAction)
presentViewController(internetAlert, animated: true, completion: nil)
return
}
DataService.dataService.USERNAME_REF.observeEventType(.Value, withBlock: { snapshot in
var usernamesMatched = false
if snapshot.value is NSNull {
usernamesMatched = false
} else {
let usernameDictionary = snapshot.value
let usernameArray = Array(usernameDictionary.allKeys as! [String])
for storedUserName in usernameArray {
if storedUserName == self.usernameField.text! {
usernamesMatched = true
self.signupErrorAlert("Username Already Taken", message: "Please try a different username")
}
}
}
if !usernamesMatched {
// Set Email and Password for the New User.
DataService.dataService.BASE_REF.createUser(email, password: password, withValueCompletionBlock: { error, result in
if error != nil {
print("Error: \(error)")
if let errorCode = FAuthenticationError(rawValue: error.code) {
switch (errorCode) {
case .EmailTaken:
self.signupErrorAlert("Email In Use", message: "An account has already been created for this email address.")
default:
self.signupErrorAlert("Oops!", message: "Having some trouble creating your account. Please try again or check your internet connection.")
}
}
} else {
// Create and Login the New User with authUser
DataService.dataService.BASE_REF.authUser(email, password: password, withCompletionBlock: {
err, authData in
let user = ["provider": authData.provider!, "email": email!, "username": username!]
let userData = [username!: authData.uid!]
// Seal the deal in DataService.swift.
DataService.dataService.createNewAccount(authData.uid, user: user)
DataService.dataService.addUsernameToUsernamePath(userData)
})
Related
I want to verify users that sign in with email and password with a verification email in firebase.
this is my code:
#IBAction func Login(_ sender: Any) {
guard let email = txtUser.text, email != "",
let password = txtPass.text, password != ""
else {
AlertController.showAlert(self, title: "Missing Info", message: "Please fill out all required fields")
return
}
Auth.auth().signIn(withEmail: txtUser.text!, password: txtPass.text!, completion: { (authResult,error) in
if error != nil{
AlertController.showAlert(self, title: "Error", message: error!.localizedDescription)
} else if authResult != nil {
self.performSegue(withIdentifier: "SegueMode", sender: self)
}
})
}
Have you tried this
Auth.auth().sendSignInLink(toEmail:email,
actionCodeSettings: actionCodeSettings) { error in
// ...
if let error = error {
self.showMessagePrompt(error.localizedDescription)
return
}
// The link was successfully sent. Inform the user.
// Save the email locally so you don't need to ask the user for it again
// if they open the link on the same device.
UserDefaults.standard.set(email, forKey: "Email")
self.showMessagePrompt("Check your email for link")
// ...
}
Here is Function that i used in my project
(Note: Change according to your requirement!)
func loginUser() {
guard let email = txtUserName.text, let password = txtPassword.text else { return }
Auth.auth().signIn(withEmail: email, password: password, completion: { (user, error) in
if let error = error {
print(error.localizedDescription)
self.lblSuccess.isHidden = false
self.lblSuccess.textColor = UIColor.red
self.lblSuccess.text = "Invalid Credential Please Check Your Email and password"
}else if let user = Auth.auth().currentUser {
let listVC = self.storyboard?.instantiateViewController(withIdentifier: "UserListVC") as! UserListVC
print(user)
self.lblSuccess.isHidden = false
self.lblSuccess.textColor = UIColor.green
self.lblSuccess.text = "Login SuccessFully!!"
self.navigationController?.pushViewController(listVC, animated: true)
}
})
}
#objc func registerButtonClicked()
{
//After Firebase is configured this is called
guard let email = emailTextField.text else {
alertBox(title: "Error", message: "All fields are mandatory")
return }
guard let password = passwordTextField.text else { return }
guard let name = nameTextField.text else { return }
Auth.auth().createUser(withEmail: email, password: password) { (data, error) in
if error != nil{
print(error.debugDescription)
print("Error occurred")
} else
{
print("Data -- >\(String(describing: data))")
self.saveDataInFirebase(name: name, password: password, email: email)
//here the data is saved in authentication table in firebase so next step //was to save its detail in db in json
}
}
}
func saveDataInFirebase(name: String, password: String, email: String)
{
let userData = ["name" : name, "email" : email]
print("name \(name) --- Email \(email)")
// printing the details to be saved in DB
let firebaseRef = Database.database().reference(fromURL: "https://chatdemo1-d3423.firebaseio.com/")
firebaseRef.updateChildValues(userData) { (error, dbRef) in
if error != nil{
print("------------------")
print(error.debugDescription)
print("----------------------")
}
else
{
print("Data Saved Successfully")
}
}
}
The code in the question is probably not what you want to use as it will overwrite your entire Firebase each time it's run.
The reason for that is you're not writing data to a child node of your Firbase, you are writing it to the main node. This is what's being written:
your_firebase //<- this is where you're writing too each time
email: "some email"
name: "some name"
my guess is you want to stucture it like this
your_firebase
user_id
email: "some email"
name: "some name"
and the code to do that would be
var ref: DatabaseReference!
func viewDidLoad() {
self.ref = Database.database().reference()
.
.
.
}
func createUser() {
let email = "some email"
let password = "some password"
let name = "some name"
Auth.auth().createUser(withEmail: email, password: password) { (authResult, error) in
if let x = error { //some fancy error checking
let err = x as NSError
switch err.code {
case AuthErrorCode.emailAlreadyInUse.rawValue:
print("email in use!")
default:
print("unknown error")
}
} else {
guard let user = authResult?.user else { return }
let uid = user.uid
let usersRef = self.ref.child("users")
let thisUserRef = usersRef.child(uid)
thisUserRef.child("email").setValue(email)
thisUserRef.child("name").setValue(name)
}
}
}
This code assumes the Firebase Rules allows the user permission to write the the users node
I've been trying to figure this problem out for a few days and can't seem to find a solution that works.
The problem is: When I try to create an account in my app, it automatically creates an account without entering any information. So basically the user puts no info and the account is still being created.
I'm currently using Firebase
Here is the code for that View:
import UIKit
import Firebase
class createAccountVC: UIViewController {
private let RIDER_SEGUE = "createAccountSegue"
#IBOutlet weak var emailTextField: UITextField!
#IBOutlet weak var passwordTextField: UITextField!
#IBOutlet weak var confirmPasswordTextField: UITextField!
#IBOutlet weak var createAccountButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
createAccountButton.titleLabel?.numberOfLines = 2
createAccountButton.titleLabel?.lineBreakMode = NSLineBreakMode.byWordWrapping
}
private func alertTheUser(title: String, message: String) {
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
let ok = UIAlertAction(title: "OK", style: .default, handler: nil)
alert.addAction(ok)
present(alert, animated: true, completion: nil)
}
#IBAction func signUp(_ sender: AnyObject) {
if emailTextField.text != "" && passwordTextField.text != "" && confirmPasswordTextField.text != "" {
AuthProvider.Instance.signUp(withEmail: emailTextField.text!, password: passwordTextField.text!, loginHandler: { (message) in
if message != nil {
self.alertTheUser(title: "Problem with creating a new user.", message: message!)
} else {
GroomrHandler.Instance.rider = self.emailTextField.text!
self.saveUserInfo(email: self.emailTextField.text!, password: self.passwordTextField.text!)
self.emailTextField.text = ""
self.passwordTextField.text = ""
self.confirmPasswordTextField.text = ""
//self.performSegue(withIdentifier: self.RIDER_SEGUE, sender: nil)
// save password to keychain
}
})
} else {
alertTheUser(title: "Email and password are required.", message: "Please enter email and password in the text fields.")
}
}
func saveUserInfo(email: String, password: String) {
//save login info in app
UserDefaults.standard.set(email, forKey: "email")
}
}
Thank you in advance! Don't flame me, I'm still learning XD
EDIT: Here is the AuthProvider File:
import Foundation
import Firebase
typealias LoginHandler = (_ msg: String?) -> Void
struct LoginErrorCode {
static let INVALID_EMAIL = "Invalid email address, please provide a real email address."
static let WRONG_PASSWORD = "Wrong password, please enter the correct password."
static let PROBLEM_CONNECTING = "Problem connecting to database, please try later."
static let USER_NOT_FOUND = "User not found, please register."
static let EMAIL_ALREADY_IN_USE = "Email already in use, please use another email."
static let WEAK_PASSWORD = "Password should be at least 6 characters long."
}
class AuthProvider {
private static let _instance = AuthProvider()
static var Instance: AuthProvider {
return _instance
}
func login(withEmail: String, password: String, loginHandler: LoginHandler?) {
Auth.auth().signIn(withEmail: withEmail, password: password, completion: { (user, error) in
if error != nil {
self.handleErrors(err: error! as NSError, loginHandler: loginHandler)
} else {
loginHandler?(nil)
}
})
} // login func
func signUp(withEmail: String, password: String, loginHandler: LoginHandler?) {
Auth.auth().createUser(withEmail: withEmail, password: password, completion: { (user, error) in
if error != nil {
self.handleErrors(err: error! as NSError, loginHandler: loginHandler)
} else {
if user?.uid != nil {
// login the user
self.login(withEmail: withEmail, password: password, loginHandler: loginHandler)
}
}
})
} // sign up func
func logOut() -> Bool {
if Auth.auth().currentUser != nil {
do {
try Auth.auth().signOut()
return true
} catch {
return false
}
}
return true
}
private func handleErrors(err: NSError, loginHandler: LoginHandler?) {
if let errCode = AuthErrorCode(rawValue: err.code) {
switch errCode {
case .wrongPassword:
loginHandler?(LoginErrorCode.WRONG_PASSWORD)
break
case .invalidEmail:
loginHandler?(LoginErrorCode.INVALID_EMAIL)
break
case .userNotFound:
loginHandler?(LoginErrorCode.USER_NOT_FOUND)
break
case .emailAlreadyInUse:
loginHandler?(LoginErrorCode.EMAIL_ALREADY_IN_USE)
break
case .weakPassword:
loginHandler?(LoginErrorCode.WEAK_PASSWORD)
break
default:
loginHandler?(LoginErrorCode.PROBLEM_CONNECTING)
break
}
}
}
} // class
I had some experience in registering users, here is my code, you may try it. Hope that it helps.
This in User object:
Auth.auth().createUser(withEmail: email, password: password, completion: { (user, error) in
if error == nil {
user?.sendEmailVerification(completion: nil)
let storageRef = Storage.storage().reference().child("usersProfilePics").child(user!.uid)
let imageData = UIImageJPEGRepresentation(profilePic, 0.1)
storageRef.putData(imageData!, metadata: nil, completion: { (metadata, err) in
if err == nil {
let path = metadata?.downloadURL()?.absoluteString
let values = ["name": withName, "email": email, "profilePicLink": path!]
Database.database().reference().child("users").child(userType).child((user?.uid)!).child("credentials").updateChildValues(values, withCompletionBlock: { (errr, _) in
if errr == nil {
let userInfo = ["email" : email, "password" : password, "type" : userType]
UserDefaults.standard.set(userInfo, forKey: "userInformation")
completion(true)
}
})
}
})
}
else {
completion(false)
}
})
Here I am calling method of User object:
User.registerUser(withName: self.registerNameField.text!, email: self.registerEmailField.text!, password: self.registerPasswordField.text!, profilePic: self.profilePicView.image!, forUserType: UserType.psychologist) { [weak weakSelf = self] (status) in
DispatchQueue.main.async {
weakSelf?.showLoading(state: false)
for item in self.inputFields {
item.text = ""
}
if status == true {
weakSelf?.pushTomainView()
weakSelf?.profilePicView.image = UIImage.init(named: "profile pic")
} else {
for item in (weakSelf?.waringLabels)! {
item.isHidden = false
}
}
}
}
var abcd: String?
if abcd != "" {
print("hello")
}
The above code prints hello in the console. Similar issue is happening in your code. condition abcd != "" only test for empty, not nil. You should first unwrap all textfield text, then check for isEmpty, and create account.
#IBAction func signUp(_ sender: AnyObject) {
guard let email = emailTextField.text,
let password = passwordTextField.text,
let confirmPassword = confirmPasswordTextField.text,
email != "",
password != "",
confirmPassword != "" else {
alertTheUser(title: "Email and password are required.", message: "Please enter email and password in the text fields.")
}
AuthProvider.Instance.signUp(withEmail: email, password: password, loginHandler: { (message) in
if message != nil {
self.alertTheUser(title: "Problem with creating a new user.", message: message!)
} else {
GroomrHandler.Instance.rider = email
self.saveUserInfo(email: email, password: password)
self.emailTextField.text = ""
self.passwordTextField.text = ""
self.confirmPasswordTextField.text = ""
//self.performSegue(withIdentifier: self.RIDER_SEGUE, sender: nil)
// save password to keychain
}
})
}
According to Firebase site, I am using this code to create a new user:
firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {});
How can I add display name and photo url to Auth when creating the new user?
This link shows the supported user data returned from an identity provider in Auth.
You can update your profile with FIRUserProfileChangeRequest class .. check this Doc.
let user = FIRAuth.auth()?.currentUser
if let user = user {
let changeRequest = user.profileChangeRequest()
changeRequest.displayName = "Jane Q. User"
changeRequest.photoURL =
NSURL(string: "https://example.com/jane-q-user/profile.jpg")
changeRequest.commitChangesWithCompletion { error in
if let error = error {
// An error happened.
} else {
// Profile updated.
}
}
}
I think this should solve it for you, let me know if you need anything else. or have any further questions on this matter.
func handleSignUp() {
guard let userName = userNameTF.text else { return }
guard let email = emailTF.text else { return }
guard let password = passwordTF.text else { return }
guard let image = profileImage.image else { return }
continueButton.setBackgroundImage(#imageLiteral(resourceName: "inactiveButtonBG"), for: .normal)
activityIndicator.startAnimating()
Auth.auth().createUser(withEmail: email, password: password) { user, error in
if error == nil && user != nil {
print("User created!")
self.uploadProfileImage(image: image) { url in
if url != nil {
let changeRequest = Auth.auth().currentUser?.createProfileChangeRequest()
changeRequest?.displayName = userName
changeRequest?.photoURL = url
changeRequest?.commitChanges { error in
if error == nil {
self.saveProfile(username: userName, profileImageURL: url!) { success in
if success {
print("Success upload of profile image")
self.dismiss(animated: true, completion: nil)
}
}
self.dismiss(animated: true, completion: nil)
} else {
guard let message = error?.localizedDescription else { return }
self.userAlert(message: message)
}
}
} else {
self.userAlert(message: "Unable to load profile image to Firebase Storage.")
}
}
self.dismiss(animated: true, completion: nil)
} else {
guard let message = error?.localizedDescription else { return }
self.userAlert(message: message)
}
}
}
To change/add the display name:
user!.createProfileChangeRequest().displayName = "Your name"
To change/add photoURL
user!.createProfileChangeRequest().photoURL = URL(string: "image url")
Simply you can solve your problem as follow.
1) Create a user using following statement.
firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {});
2) success of above statement Please authenticate this user as follow.
self.rootRef.authUser(email, password)
// USER_ID = Here you get user_ID
3) Success of above function set user name and profile picture to user as follow.
usersRef.updateChildValues(dict, withCompletionBlock:
-Here userRef contain your userDetails/USER_ID
Might be work for you.
i have code but work for older firebase version so not work for you otherwise i had share with you.
I think you mean adding display name and photo url to Firebase Database after Auth. This is pretty much what I do all on same registration.
if let email = emailField.text where email != "", let pwd = passwordField.text where pwd != ""{
FIRAuth.auth()?.createUserWithEmail(email, password: pwd, completion: { (user, error) in
if error != nil {
print("DEVELOPER: Unable to authenticate with Firebase using email")
}else {
print("DEVELOPER: Successfully authenticated with Firebase using email")
if let user = user {
let userData = ["provider": user.providerID, "userName": "\(user.displayName)", "profileImg": "\(user.photoURL)"]
self.completeMySignIn(user.uid, userData: userData)
}
}
})
} else {
// Email and Password where not filled in
}
}
Now adding your profile image and users username in DB here
func completeMySignIn(id: String, userData: Dictionary<String, String>){
{YourFirebaseUserURL}.updateChildValues(userData)
}
You can use the Firebase Admin SDK in Firebase Function exactly for your purpose, i.e. to fill up other user properties as the user is created:
const admin = require("firebase-admin");
// Put this code block in your Firebase Function:
admin.auth().createUser({
email: email,
emailVerified: false,
password: password,
displayName: `${fname} ${lname}`,
disabled: false
})
But creating user with Firebase Admin SDK may give you problem in sending email verification because the promise does not return the User object that has the sendEmailVerification() method. You may eventually need to use the Firebase client API (as shown in your own code) to create the user and update the user profile before sending the email verification:
var user = firebase.auth().currentUser;
user.updateProfile({
displayName: "Jane Q. User",
photoURL: "https://example.com/jane-q-user/profile.jpg"
}).then(function() {
// Update successful.
}).catch(function(error) {
// An error happened.
});
It make sense to update the displayName before sending email verification so that the Firebase email template will greet the new user with proper name rather than just Hello (sounds like a spam) when the displayName is not set.
I am new to firebase and I'm trying to learn how to create users. My problem is that when i use the createUserWithEmail completion block via a button, for some reason the unique identifier, the uid, is not generated. This prevents me from storing the associated username and password under the uid in the JSON tree. My code is as follows (I have defined databaseRef in a separate swift file as a global constant using "let databaseRef = FIRDatabase.database().reference()")
#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")
}
}
I know the uid is not generated for two reasons. Firstly, when i run the above code and enter in values for each of my texts fields, the app crashes. Secondly, if i delete the code that deals with setting the values and replace it with print(user.uid), a value of nil is returned. What am i missing? I can understand that the uid is a very important part of creating a user.
***Here is the solution I came up with
#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")
}
Swift 4, 2018 solution for anyone who's interested:
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.child("users").child(user.uid).setValue(userObject)
}
Swift 5.1, 2022 solution for anyone who's interested:
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 userObj = ["uid": user.user.uid, "username": username, "email": email] as [String:Any]
databaseRef.child("users/\(user.user.uid))".setValue(userObj)