将自定义属性添加到Firebase身份验证
我搜寻了Firebase的文档,似乎找不到找到将自定义属性添加到FIRAuth的方法。我正在从Parse-Server迁移应用程序,并且我知道可以设置用户的用户名,电子邮件和objectId。不,我看到我可以选择使用电子邮件,displayName和photoURL。我希望能够添加自定义属性,例如用户名。例如,我可以使用:
I have hunted through Firebase's docs and can't seem to find a way to add custom attributes to FIRAuth. I am migrating an app from Parse-Server and I know that I could set a user's username, email, and objectId. No I see that I have the option for email, displayName, and photoURL. I want to be able to add custom attributes like the user's name. For example, I can use:
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.setValue("Test1Name", forKey: "usersName")
changeRequest.commitChangesWithCompletion { error in
if error != nil {
print("\(error!.code): \(error!.localizedDescription)")
} else {
print("User's Display Name: \(user.displayName!)")
print("User's Name: \(user.valueForKey("name"))")
}
}
}
运行代码时,出现错误,提示 usersName不符合键值。这不是使用正确的代码吗?我似乎找不到其他方法。
When I run the code, I get an error that "usersName" is not key value compliant. Is this not the right code to use. I can't seem to find another way.
您无法向Firebase Auth添加自定义属性。已提供默认属性,以方便访问用户信息,尤其是在使用提供程序(例如Facebook)时。
You can't add custom attributes to Firebase Auth. Default attributes have been made available to facilitate access to user information, especially when using a provider (such as Facebook).
如果您需要存储有关用户的更多信息,请使用Firebase实时数据库。我建议有一个用户父级,它将容纳所有用户子级。另外,请使用userId密钥或电子邮件密钥来识别用户并将其与各自的帐户相关联。
If you need to store more information about a user, use the Firebase realtime database. I recommend having a "Users" parent, that will hold all the User children. Also, have a userId key or an email key in order to identify the users and associate them with their respective accounts.
希望这会有所帮助。