Hab*_*man 2 javascript jquery firebase firebase-authentication
我正在按照 YT tuts 进行简单的注册,链接(https://www.youtube.com/watch?v=-OKrloDzGpU)在那里我有这个脚本,但app.js
出现错误
未捕获的类型错误:无法读取 HTMLInputElement.btnLogin.addEventListener.e (app.js:26) 处未定义的属性“signInWithEmailAndPassword”
// 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));
});
Run Code Online (Sandbox Code Playgroud)
在第 26 行,我const promise = auth.signInWithEmailAndPassword(email,pass);似乎想念包含任何auth库,但我已将脚本包含在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>
Run Code Online (Sandbox Code Playgroud)
它应该是
firebase.auth().signInWithEmailAndPassword
检查此处的文档。
https://firebase.google.com/docs/reference/js/firebase.auth.Auth#signInWithEmailAndPassword
更新
根据您提到的视频,这在您的示例中设置错误
const auth = firebase.value;
Run Code Online (Sandbox Code Playgroud)
它应该是
const auth = firebase.auth();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12045 次 |
| 最近记录: |