admin管理员组

文章数量:1300069

I'm doing simple signup by following YT tuts, link () There i have this script in app.js
and i'm getting error

Uncaught TypeError: Cannot read property 'signInWithEmailAndPassword' of undefined at HTMLInputElement.btnLogin.addEventListener.e (app.js:26)

// GET Users info
const txtEmail    = document.getElementById('txtEmail');
const txtPassword = document.getElementById('txtPassword');
const btnLogin    = document.getElementById('btnLogin');
const btnSignUp   = document.getElementById('btnSignUp');
const btnLogout   = document.getElementById('btnLogout');

//Add login event
btnLogin.addEventListener('click', e =>{
  "use strict";
  const email = txtEmail.value;
  const pass  = txtPassword.value;
  const auth  = firebase.value;

  // Sign in
  const promise = auth.signInWithEmailAndPassword(email,pass);
  promise.catch(e => console.log(e.message));

});

and on line 26 i have const promise = auth.signInWithEmailAndPassword(email,pass); seems like i miss including any auth library but i have included scripts in index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Smart Media Compaing</title>

    <script src=".0.0/firebaseui.js"></script>
    <link type="text/css" rel="stylesheet" href=".0.0/firebaseui.css" />

    <script src=".6.1/firebase-app.js"></script>
    <script src=".6.1/firebase-auth.js"></script>
    <script src=".6.1/firebase-database.js"></script>
    <script src=".6.1/firebase-messaging.js"></script>

    <script src=".6/firebase.js"></script>
    <link rel="stylesheet" type="text/css" href="style.css">
  </head>
  <body>
    <div id="message">
      <input type="email" id="txtEmail" name="user_email" placeholder="Email">
      <input type="password" name="user_password" id="txtPassword" placeholder="Password">
      <input type="button" id="btnLogin" class="btn btn-action" value="Login" name="submit">
      <button id="btnSignup" class="btn btn-secondary">
        Sign Up
      </button>
      <button id="btnLogout" class="btn btn-action hide">
        Log Out
      </button>
    </div>
    <script type="text/javascript" src="app.js"></script>
  </body>
</html>

I'm doing simple signup by following YT tuts, link (https://www.youtube./watch?v=-OKrloDzGpU) There i have this script in app.js
and i'm getting error

Uncaught TypeError: Cannot read property 'signInWithEmailAndPassword' of undefined at HTMLInputElement.btnLogin.addEventListener.e (app.js:26)

// GET Users info
const txtEmail    = document.getElementById('txtEmail');
const txtPassword = document.getElementById('txtPassword');
const btnLogin    = document.getElementById('btnLogin');
const btnSignUp   = document.getElementById('btnSignUp');
const btnLogout   = document.getElementById('btnLogout');

//Add login event
btnLogin.addEventListener('click', e =>{
  "use strict";
  const email = txtEmail.value;
  const pass  = txtPassword.value;
  const auth  = firebase.value;

  // Sign in
  const promise = auth.signInWithEmailAndPassword(email,pass);
  promise.catch(e => console.log(e.message));

});

and on line 26 i have const promise = auth.signInWithEmailAndPassword(email,pass); seems like i miss including any auth library but i have included scripts in index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Smart Media Compaing</title>

    <script src="https://cdn.firebase./libs/firebaseui/1.0.0/firebaseui.js"></script>
    <link type="text/css" rel="stylesheet" href="https://cdn.firebase./libs/firebaseui/1.0.0/firebaseui.css" />

    <script src="https://www.gstatic./firebasejs/3.6.1/firebase-app.js"></script>
    <script src="https://www.gstatic./firebasejs/3.6.1/firebase-auth.js"></script>
    <script src="https://www.gstatic./firebasejs/3.6.1/firebase-database.js"></script>
    <script src="https://www.gstatic./firebasejs/3.6.1/firebase-messaging.js"></script>

    <script src="https://www.gstatic./firebasejs/live/3.6/firebase.js"></script>
    <link rel="stylesheet" type="text/css" href="style.css">
  </head>
  <body>
    <div id="message">
      <input type="email" id="txtEmail" name="user_email" placeholder="Email">
      <input type="password" name="user_password" id="txtPassword" placeholder="Password">
      <input type="button" id="btnLogin" class="btn btn-action" value="Login" name="submit">
      <button id="btnSignup" class="btn btn-secondary">
        Sign Up
      </button>
      <button id="btnLogout" class="btn btn-action hide">
        Log Out
      </button>
    </div>
    <script type="text/javascript" src="app.js"></script>
  </body>
</html>
Share Improve this question asked Dec 17, 2016 at 15:12 Habib RehmanHabib Rehman 6183 gold badges15 silver badges37 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

It should be

firebase.auth().signInWithEmailAndPassword

Check the documentation here.

https://firebase.google./docs/reference/js/firebase.auth.Auth#signInWithEmailAndPassword

UPDATE

As per the video you have mentioned , this is wrongly set in your example

const auth  = firebase.value;

it should be

const auth  = firebase.auth();

You need to initialize your app then call auth() correctly.

var config = {
    apiKey: "<API_KEY>",
    authDomain: "<PROJECT_ID>.firebaseapp.",
    databaseURL: "https://<DATABASE_NAME>.firebaseio.",
    storageBucket: "<BUCKET>.appspot.",
    messagingSenderId: "<SENDER_ID>",
};
firebase.initializeApp(config);

Then call firebase.auth().signInWithEmailAndPassword

https://firebase.google./docs/web/setup

本文标签: javascriptFirebase Uncaught TypeError Cannot read property 39signInWithEmailAndPassword39Stack Overflow