[英]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,如果您将参考文档放在手边: JavaScript 、 Java ,这应该不会太难。
I actually just noticed that the Firebase documentation also have guides on how to do this for Java and JavaScript .我实际上只是注意到 Firebase 文档也有关于如何为Java和JavaScript执行此操作的指南。 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.