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