简体   繁体   English

如何检查登录 Firebase 用户是否有密码

[英]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.

相关问题 如何确定用户是否已在Firebase中使用电子邮件进行了注册? - How to determine if the user has signed up using email in Firebase? 如何检查用户是否刚刚在 firebase 中首次登录 Google - How to check if A user just Google signed in for first time in firebase 检查用户是否已登录 Firebase 通过电话号码进行身份验证 - Check if user is already signed in to Firebase Authentication by phone number 如果用户已注销,我如何允许用户更改其密码? - How can I allow a user to change his password if they are signed out? 如何在android中检查设备是否设置了密码? - How to check the device has set password or not in android? 如何使用 Firebase 检索已登录用户的 UID 下的数据 - How do I retrieve data under UID for the signed in user with Firebase 如何从当前登录用户 Firebase,Android 中检索值 - How to retrieve values from current signed in User Firebase,Android 如何检查我的Firebase数据库是否具有特定用户的数据? (Android / Java) - How can I check if my Firebase database has data for a certain user? (Android/Java) 如何从文本文件检查用户名和密码以登录页面 - how check user and password from textfile for loginpage 为什么我必须在用户登录后使用 firebase 对其进行身份验证? - Why do I have to authenticate the user with firebase after he has already signed-in?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM