简体   繁体   English

Firebase-网络。 无法显示登录用户的图片

[英]Firebase - Web. Can not display logged user's picture

I'm not able to display the picture of a logged user with email/password inside an <img> tag. 我无法在<img>标记内显示带有电子邮件/密码的登录用户的图片。 I could display correctly the email,uid and all the details but the picture. 我可以正确显示电子邮件,uid和除图片以外的所有详细信息。 This is the code: 这是代码:

HTML: HTML:

<img id="user-image">   

Js: JS:

firebase.auth().onAuthStateChanged(function(user) {
  var userId = firebase.auth().currentUser;
  var picture;
  if (userId) {
    picture = userId.photoURL;
    document.getElementById("user-image").src = picture;
  } else {
    //Nothing;
  }
});

When I go to the console I get error 404/null. 当我转到控制台时,出现错误404 / null。 Yes, the user Do have a picture ,I tried already with the exact path of the image file and it works. 是的,用户确实有图片,我已经尝试了使用图像文件的确切路径,并且可以正常工作。

Thanks. 谢谢。

Why do you call firebase.auth().currentUser; 为什么调用firebase.auth().currentUser; when you already have the user as a parameter of the function that is triggered on change? 当您已经将用户作为更改时触发的功能的参数时?

What do you get if you do as follows: 如果执行以下操作,将会得到什么:

firebase.auth().onAuthStateChanged(function(user) {
  if (user) {
    var picture = user.photoURL;
    console.log(picture). // <- check in you console that you get the correct url
    document.getElementById("user-image").src = picture;
  } else {
    //Nothing;
  }
});

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

相关问题 FIREBASE phoneAuth (LinkWithPhoneNumber)。 稍后如何在 Firebase Web 中更改用户的关联电话号码。 ( nodejs, Create-react-app )? - FIREBASE phoneAuth ( LinkWithPhoneNumber ) . How to change a user's linked phone number later in Firebase Web. ( nodejs, Create-react-app )? Firebase 网站。 没有 signInWithUsernameAndPassword 功能 - Firebase web. No signInWithUsernameAndPassword function Angularjs - Firebase 显示当前登录的用户数据 - Angularjs - Firebase display current logged in user's data Firebase 消息 web。多标签通知 - Firebase messaging for web. Multiple tabs notifications Javascript-使用Facebook登录,成功登录后显示用户的个人资料图片 - Javascript - Login with Facebook, display user's profile picture after logged in successfully Web的Firebase:告知用户是否已登录 - Firebase for web: telling whether user is logged in or not Firebase网站。 检查数组中的对象是否具有特定值 - Firebase web. Checking if an object in an array has a particular value Firebase用户已登录 - Firebase User Already Logged In 使用 Firebase web 的用户信息显示错误 - User info display error using Firebase web 如何检索当前从 Firestore/Firebase 登录的用户信息? - How to retrieve the user's info that is currently logged in from Firestore/Firebase?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM