javascript - .signInWithEmailandPassword 不是函数
问题描述
我正在关注 Firebase 团队的这段视频,将 Firebase Auth 添加到我的应用程序 ( https://www.youtube.com/watch?v=-OKrloDzGpU )
我已将在 Firebase 中为我的项目生成的 Web 应用程序脚本添加到我的应用程序的 html 部分中,并且基本上复制了其他代码来进行登录和注册,如下面的代码所示
但是我收到了这个错误,我不知道它为什么会触发
TypeError: auth.signInWithEmailandPassword 不是函数。(在 'auth.signInWithEmailandPassword(email, pass)' 中,'auth.signInWithEmailandPassword' 未定义)
HTML 代码
<!DOCTYPE html> <meta charset="utf-8" />
<html>
<head>
<script src="https://www.gstatic.com/firebasejs/5.7.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.7.0/firebase-auth.js"></script>
<link rel="stylesheet" href="css/styles.css" />
</head>
<body>
<div class="container">
<input id="txtEmail" type="email" required placeholder="Email" />
<input id="txtPassword" type="password" required placeholder="Password" />
<button id="btnLogin" class="button-is-link">Login</button>
<button id="btnSignUp" class="button-is-info">Sign Up</button>
</div>
<script src="js/auth.js"></script>
</body>
</html>
Auth.js
(function() {
// Initialize Firebase
var config = {
apiKey: 'API KEY',
authDomain: 'DOMAIN',
databaseURL: 'DATABASE',
projectId: 'ID',
storageBucket: 'BUCKET',
messagingSenderId: 'ID'
};
firebase.initializeApp(config);
const txtEmail = document.getElementById('txtEmail');
const txtPassword = document.getElementById('txtPassword');
const btnLogin = document.getElementById('btnLogin');
const btnSignUp = document.getElementById('btnSignUp');
btnLogin.addEventListener('click', e => {
const email = txtEmail.value;
const pass = txtPassword.value;
const auth = firebase.auth();
const promise = auth.signInWithEmailandPassword(email, pass);
promise.catch(e => console.log('e.message'));
});
btnSignUp.addEventListener('click', e => {
const email = txtEmail.value;
const pass = txtPassword.value;
const auth = firebase.auth();
const promise = auth.createUserWithEmailandPassword(email, pass);
promise.catch(e => console.log('e.message'));
firebase.auth().onAuthStateChange(firebaseUser => {
if (firebaseUser) {
console.log('U are logged in');
} else {
console.log('Not logged in');
}
});
});
})();
解决方案
确切的方法名称是signInWithEmailAndPassword
,在 And 处带有一个大写的“A”。
与 相同createUserWithEmailAndPassword
。
推荐阅读
- javascript - 如何使用“加法混合”以外的混合模式使不透明度影响材质
- python - 在python中,GC如何处理mmap?
- regex - 正则表达式在 Atom 或 Sublime 中查找用乘数替换
- python - script-write dict 并将其写入文件然后加载
- java - 如何在 Eclipse 下获取 Java 应用程序的 JVM Monitor CPU 统计信息?
- javascript - for循环数组中的所有数字都需要显示
- c# - 如何将数据绑定到xamarin中的stacklayout
- java - 为什么这个Java小程序会让MacOS重启?
- dart - 在 Dart 中 - 是否有与 python 的检查模块类似的包?
- mysql - 如何解决共享主机的mysql高使用率问题。由于 MYSQL 高使用率,我的网站托管被暂停