Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
329 views
in Technique[技术] by (71.8m points)

javascript - Uncaught TypeError: Cannot read property 'uid' of null using website

I want to get registered user details from firestore into html page. When user clicks my profile page it navigate to next html page with fields like first name and last name etc.. . This fields are already entered at the time of signup page. so i want get those details from firestore into next html page. But i got the error like "Cannot read property 'uid' of null ". How to resolve that problem this is my html page :

<!doctype html>
<html lang="en">
    <head>
        <title> deyaPay</title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
         <script src="https://www.gstatic.com/firebasejs/4.6.2/firebase-app.js"></script>
         <script src="https://www.gstatic.com/firebasejs/4.6.2/firebase-auth.js"></script>
        <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.6/umd/popper.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js"></script>
        <script src="https://www.gstatic.com/firebasejs/4.6.2/firebase-firestore.js"></script>
         <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
         <script>
          var config = {
    apiKey: "AIzaSyAJsAstiMsrB2QGJyoqiTELw0vsWFVVahw",
    authDomain: "websignin-79fec.firebaseapp.com",
    databaseURL: "https://websignin-79fec.firebaseio.com",
    projectId: "websignin-79fec",
    storageBucket: "",
    messagingSenderId: "480214472501"
  };
   firebase.initializeApp(config);
   </script>
   <script src="https://www.gstatic.com/firebasejs/4.6.2/firebase-firestore.js"></script>
         <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
   <style>
   // css goes here..
   </style> 
   <script type="text/javascript">
      function myProfile() {
          var user = firebase.auth().currentUser.uid;
          var db = firebase.firestore();
          var docRef = db.collection("deyaPayusers").doc(user);
          docRef.get().then(function(doc) {
             if(doc && doc.exists) {
             const myData = doc.data();
             const ffname = myData.FirstName;
             const llname = myData.LastName;
             const phonen = myData.PhoneNumber;
             document.getElementById("fname").value = ffname;
             document.getElementById("lname").value = llname;
             document.getElementById("phone").value = phonen;

        }
        }).catch(function(error) {
        console.log("Got an error: ",error);
        });
      }  

    </script>
   </head>
   <body onload='myProfile()'>
      <div class= "login-form">
          <form method="post">
             <h2>Profile</h2>
              <div class="form-group">
                  <input type="text" name="firstname" id="fnmae" placeholder="FirstName" class="form-control" >
              </div>
               <div class="form-group">
                  <input type="text" name="lastname" id="lnmae" placeholder="LastName" class="form-control" >
              </div>
              <div class="form-group">
                 <input type="text" name="phone" id="phone" placeholder="PhoneNumber" class="form-control" >
              </div>

          </form>
      </div>

   </body>
 </html>                
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...