我不知道为什么 UID 返回 null。 userSessionCheck() 包含登录后保留 session 的代码。 user.uid 给出相同的结果,下面是我的代码和错误代码
--
未捕获类型错误:无法读取 null 的属性“uid”
$(document).ready(function(){
auth = firebase.auth();
db = firebase.database();
storage = firebase.storage();
userInfo = auth.currentUser;
userSessionCheck();
update_profile();
function update_profile() {
var mypage_Ref = db.ref('users/' + userInfo.uid).once('value').then(function(snapshot){
console.log(snapshot.val());
profileImageUrl = $('#update_email').val(snapshot.val().profileImageUrl);
email = $('#update_email').val(snapshot.val().email);
u_name = $('#update_name').val(snapshot.val().username);
job = $('#update_job').val(snapshot.val().job);
var html =
'<div class="profile">' +
'<img src="'+profileImageUrl+'" id="profile_img">'+
'<div class="form_g">'+
'<label>email</label>'+
'<input type="text" style="text-align: center" id="update_email" placeholder="'+ email +'">'+
'</div>'+
'<div class="form_g">'+
'<label>name</label>'+
'<input type="text" style="text-align: center" id="update_name" placeholder="'+u_name+'">'+
'</div>'+
'<div class="form_g">'+
'<label>job</label>'+
'<h5 id="update_job">'+job+'</h5>'+
'</div>'+
'<button type="button" class="s-btn" id="info_submit" style="width: 100%; margin-top: 30px;">update</button>'+
'</div>';
$('#profile_form').append(html);
});
}
});
最佳答案
userInfo = auth.currentUser
给您 null,这意味着 userInfo.uid
将给出该错误。当 auth.currentUser 为 null 时,表示没有用户登录。在新页面加载时,用户不会立即登录,因此您应该使用 auth state observer确定登录的用户帐户何时首次可用。
关于javascript - 未捕获的类型错误 : Cannot read property 'uid' of null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59129177/