没有电子邮件作为用户名的Firebase身份验证? [英] Firebase Authentication without email as username?
问题描述
是否可以在Firebase中使用字符串而不是电子邮件地址作为用户名?
Is it possible to use a string rather than email address as a username in Firebase?
我尝试过,但是 createUser
方法要求它是电子邮件地址.无论如何,我可以绕开这个限制吗?
I tried, but the createUser
method requires it to be an email address. Is there anyway I can get around this restriction?
推荐答案
鉴于Firebase电子邮件+密码身份验证无法验证电子邮件地址是否实际存在,您可以在字符串末尾填充任何域.只要结果是一个语法上有效的电子邮件地址,它将起作用:
Given that Firebase Email+Password Authentication does not verify that the email address actually exists, you can just stuff any domain at the end of your string. As long as the result is a syntactically valid email address, it will work:
var name = 'puf'; // TODO: read this from the form where the user enters their username
var password = 'geheim';
var email = name + '@whateverdomain.com';
ref.createUser({ email: email, password: password}...
请注意,用户无法使用这种方法来接收密码恢复电子邮件.
Note that the user won't have a way to receive password recovery emails with this approach.
Update there is an example of how to implement username+password sign-in in the functions-samples
repo.
这篇关于没有电子邮件作为用户名的Firebase身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!