[英]How to check if signed in Firebase user has a Password
My app uses Firebase authentication with two providers(email/password and Google SignIn) but I require all my users to have a password so they can use any of these providers to sign in, now my problem is I want that each user that sign in using a provider different from email/password should be prompted to create a password immediately but I cannot find any method in the SDK to check if a user has a password.我的应用程序使用 Firebase 身份验证和两个提供商(电子邮件/密码和 Google 登录),但我要求我的所有用户都有密码,以便他们可以使用这些提供商中的任何一个登录,现在我的问题是我希望每个登录的用户应提示使用不同于电子邮件/密码的提供商立即创建密码,但我在 SDK 中找不到任何方法来检查用户是否有密码。
I tried using the method below to check that but from my observation, this checks only for the provider the user used to Sign Up.我尝试使用以下方法进行检查,但根据我的观察,这仅检查用户用于注册的提供者。
for(UserInfo info : currentUser.getProviderData()) {
if(!info.getProviderId().equals("password")) {
ShowUpdateUserPasswordDialog("CREATE",currentUser);
} else {
MoveToMainActivity();
}
break;
}
I require all my users to have a password so they can use any of these providers to sign in
我要求我的所有用户都有密码,以便他们可以使用这些提供商中的任何一个登录
Firebase authentication with email and password is a totally different authentication mechanism than the authentication with the Google provider.使用 email 和密码的 Firebase 身份验证与使用 Google 提供商的身份验证是完全不同的身份验证机制。
now my problem is I want that each user that sign in using a provider different from email/password should be prompted to create a password immediately
现在我的问题是我希望使用不同于电子邮件/密码的提供商登录的每个用户都应该被提示立即创建密码
If the user has chosen to sign-in with Google, why would you force him to enter a password?如果用户选择使用 Google 登录,为什么要强制他输入密码? That's the whole idea, not to use a password anymore.
这就是整个想法,不再使用密码。 Besides that, you let the user choose even from the beginning what kind of authentication to use.
除此之外,您甚至可以让用户从一开始就选择使用哪种身份验证。 It's some kind of a bad user experience to force the user to choose one, or the other, or both.
强迫用户选择一个,或另一个,或两者兼而有之,这是一种糟糕的用户体验。
However, if you still want to force the user the choose a password, you first need to sign-out the user from Google and Firebase so it can be signed in again with email and password.但是,如果您仍然想强制用户选择密码,您首先需要从 Google 和 Firebase 注销用户,以便可以使用 email 和密码再次登录。 You can do that silently, but how about the situation in which the user wants to choose a password for the Gmail account that is already in use?
您可以静默执行此操作,但如果用户想要为已在使用的 Gmail 帐户选择密码,情况如何? In that situation you'll get an error, saying the account with that particular email already exists.
在这种情况下,您会收到一条错误消息,指出具有特定 email 的帐户已经存在。
but I cannot find any method in the SDK to check if a user has a password
但我在 SDK 中找不到任何方法来检查用户是否有密码
You didn't find something like that because something like that doesn't exist.你没有找到类似的东西,因为这样的东西不存在。
IMHO, some kind of operation might be considered bad practices and I cannot see any reason for doing that.恕我直言,某种操作可能被认为是不好的做法,我看不出有任何理由这样做。 You should let the user choose the type of authentication according to their own will.
您应该让用户根据自己的意愿选择认证类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.