简体   繁体   English

如何在反应中检查用户是否使用密码方法登录?

[英]How to check if user is logged in using password method in react?

I want to add password change functionality which is only visible to users logged with email/password.我想添加密码更改功能,该功能仅对使用电子邮件/密码登录的用户可见。 I am also getting my user from the onAuthChanged method called in useEffect which runs on the app initialize.我也越来越从我的用户onAuthChanged调用方法useEffect运行在应用程序初始化。

I implemented code based on this question我根据这个问题实现了代码

here is what I've tried:-这是我尝试过的:-

useEffect(() => {
    firebaseAuth().onAuthStateChanged((user) => {
      if(user){
        for (UserInfo userinf: FirebaseAuth.getInstance().getCurrentUser().getProviderData()) {
          if (userinf.getProviderId().equals("password")) {
              System.out.println("User is signed in with email/password");
          }
      }
},[]);

But there is no Object named FirebaseAuth in 'firebase' library.但是“firebase”库中没有名为 FirebaseAuth 的对象。

You're trying to add Java code to your JavaScript project, which won't work.您正在尝试将 Java 代码添加到您的 JavaScript 项目中,但这是行不通的。

You'll have to convert the Java code you found to JavaScript, which shouldn't be too hard if you keep the reference documentation for both handy: JavaScript , Java .您必须将找到的 Java 代码转换为 JavaScript,如果您将参考文档放在手边: JavaScriptJava ,这应该不会太难。

I actually just noticed that the Firebase documentation also have guides on how to do this for Java and JavaScript .我实际上只是注意到 Firebase 文档也有关于如何为JavaJavaScript执行此操作的指南。 The latter contains this handy code snippet:后者包含这个方便的代码片段:

var user = firebase.auth().currentUser;

if (user != null) {
  user.providerData.forEach(function (profile) {
    console.log("Sign-in provider: " + profile.providerId);
    console.log("  Provider-specific UID: " + profile.uid);
    console.log("  Name: " + profile.displayName);
    console.log("  Email: " + profile.email);
    console.log("  Photo URL: " + profile.photoURL);
  });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检查用户是否使用 React 和 Embedded RuBy (erb) 登录? - How to check if user logged in using React and Embedded RuBy (erb)? 在反应中使用 firebase 检查用户是否登录 - Check if user is logged in or not using firebase in react 如何检查用户是否使用JWT登录reactjs - How to Check if the user is logged in on reactjs using JWT (Meteorjs / React)检查用户是否已登录 - (Meteorjs/React) check if user is logged in 检查用户是否已登录React Js - Check if user is logged in React Js 如何检查我的反应应用程序中当前登录的用户类型? 使用 redux 工具包进行我的 state 管理 - How to check what type of user is currently logged in my react app? Using redux toolkit for my state managment 使用laravel身份验证时,如何检查用户是否已在“反应”组件中“登录”? - How do I check if user is 'logged in' in a react component when using laravel authentication? 如何检查用户是否已登录以及如何保存其信息? (反应) - How to check if a user is logged in and how to save their information? (React) React:如何检查用户登录的次数? - React: how to check how many times a user logged in? 如何在react js中检查用户是否是第一次登录 - How to check if user has logged in for the first time in react js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM