Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过用户名登录:Firebase,Swift_Swift_Firebase_Firebase Authentication - Fatal编程技术网

通过用户名登录:Firebase,Swift

通过用户名登录:Firebase,Swift,swift,firebase,firebase-authentication,Swift,Firebase,Firebase Authentication,我想让用户登录与电子邮件,也与用户名 使用Firebase是否可能实现这一点?完全将您的用户帐户与任何类型的特定于域的身份验证凭据分离可能会让您以后感到非常痛苦(最肯定的是):- 更新您的用户密码 隐私权 更好的方法是使用电子邮件ID和唯一用户名注册用户,然后为用户提供使用用户名或电子邮件ID登录的选项 将另一个节点添加到JSON树:- {... usernameEmailLink:{ uniqueUserName1:emailID1, uniqueUserName2:e

我想让用户登录与电子邮件,也与用户名
使用Firebase是否可能实现这一点?

完全将您的用户帐户与任何类型的特定于域的身份验证凭据分离可能会让您以后感到非常痛苦(最肯定的是):-

  • 更新您的用户密码
  • 隐私权
更好的方法是使用
电子邮件ID
唯一用户名注册用户,然后为用户提供使用用户名或电子邮件ID登录的选项

将另一个节点添加到JSON树:-

{...

usernameEmailLink:{

    uniqueUserName1:emailID1,
    uniqueUserName2:emailID2, 
    uniqueUserName3:emailID3 

      }
 ...}
更新此节点的安全规则:-

{".rules":{

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

  "usernameEmailLink" :{

    ".read" : "true",
    ".write" : "auth != null" 
     }
   }
 }
代码:-

func retrieveUserEmail(userName : String, completionBlock : ((userEmail : String) -> Void)){

    var userEmail : String!

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


    userEmail = snap.value! //This will give you the email ID for the user.

     /*
       completionBlock(snap.value!)   // A even better way if this is all this function does.
     */
    })
   print(userEmail)    

}
要保存键值对,请执行以下操作:-

FIRDatabase.database().reference().child("usernameEmailLink").updateChildValues["\(userName)" : "\(Email)"]

PS:-但在此之前,请确保您的用户名是唯一的。

是的,您可以在firebase文档中找到这些信息,这些信息经过了很好的解释,并且是一个很好的教程,可以一步一步地向您展示如何做到这一点@ronatory谢谢您,但我有一条路,它只允许您通过电子邮件登录,我想用“用户名”登录好的,那么这个答案可能会对你有所帮助。在问这些问题之前,请多做一些研究questions@ronatory这不是一个好的解决方案,因为它允许用户输入用户名,然后将其保存为假电子邮件user@appname.com在该解决方案中,用户只能使用用户名登录,而不能使用真正的电子邮件,用户无法重置其密码,因为它在数据库中不是以真实电子邮件的形式存储的,我想要的是让他用“电子邮件”和“用户名”签名,我找不到任何类似的问题来解释我为什么要问它。我如何将这两个值设置在一起,如“uniqueUserName1:emailID1”?我得到了这些错误“错误保存规则-第6行:预期的”,“或”}”。这个错误发生在“usernameEmailLink”这一行:{我已经更新了规则…只需复制并粘贴它…非常感谢。应该注意的是,这使得用户的电子邮件地址可以公开访问。