Firebase:未捕获TypeError:无法读取属性'signInWithEmailAndPassword' [英] Firebase: Uncaught TypeError: Cannot read property 'signInWithEmailAndPassword'
问题描述
我正在按照YT tuts进行简单的注册,链接( https:// www .youtube.com / watch?v = -OKrloDzGpU )
我在 app.js
中有这个脚本,我得到了错误
I'm doing simple signup by following YT tuts, link (https://www.youtube.com/watch?v=-OKrloDzGpU)
There i have this script in app.js
and i'm getting error
未捕获TypeError:无法在HTMLInputElement.btnLogin.addEventListener.e中读取未定义
的属性'signInWithEmailAndPassword'
(app.js:26)
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));
});
和第26行我有 const promise = auth.signInWithEmailAndPassword(电子邮件,传递);
似乎我想念包括任何 auth
库,但我在 index.html $ c中包含了脚本$ c>
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.com/libs/firebaseui/1.0.0/firebaseui.js"></script>
<link type="text/css" rel="stylesheet" href="https://cdn.firebase.com/libs/firebaseui/1.0.0/firebaseui.css" />
<script src="https://www.gstatic.com/firebasejs/3.6.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.6.1/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.6.1/firebase-database.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.6.1/firebase-messaging.js"></script>
<script src="https://www.gstatic.com/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>
推荐答案
应该是
firebase.auth()。signInWithEmailAndPassword
firebase.auth().signInWithEmailAndPassword
请查看此处的文档。
< a href =https://firebase.google.com/docs/reference/js/firebase.auth.Auth#signInWithEmailAndPassword =nofollow noreferrer> https://firebase.google.com/docs/reference/js /firebase.auth.Auth#signInWithEmailAndPassword
更新
根据您提到的视频,在您的示例中错误地设置了
As per the video you have mentioned , this is wrongly set in your example
const auth = firebase.value;
它应该是
const auth = firebase.auth();
这篇关于Firebase:未捕获TypeError:无法读取属性'signInWithEmailAndPassword'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!