Basil Basil - 1 year ago 115
Swift Question

Sign In by UserName : Firebase,Swift

I want to let user sign in with Email and also with User Name
Is that possible using Firebase ?

Answer Source

Completely separating your users account from any kind of domain specific auth credential might be a real pain later(Most definitely):-

  • Updating your user password
  • Privacy

A better approach is to sign up your user with an email-ID and a unique userNameCheck if userName Already exists :Firebase, Swift, Then give your user option to Log In with a username or emailID.

Add another node to your JSON tree:-





Update your security rules for this node:-


 ".read" : "auth != null",
 ".write" : "auth != null",

  "usernameEmailLink" :{

    ".read" : "true",
    ".write" : "auth != null" 


func retrieveUserEmail(userName : String){

    FIRDatabase.database().reference().child("usernameEmailLink/\(userName)").observeSingleEvent(of: .value, with: {(snap) in

    print(snap.value!) //This will give you the email ID for the user.



For saving the key-value pair:-

FIRDatabase.database().reference().child("usernameEmailLink").setValue["\(userName)" : "\(Email)"]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download