gpt4 book ai didi

javascript - 如何使用android firebase数据库将firebase集成到webapp中?

转载 作者:行者123 更新时间:2023-11-28 03:43:24 24 4
gpt4 key购买 nike

android 数据库已创建,我想使用 html 页面对其进行身份验证。下面给出了它不工作的代码。这里基本上我们有一个 html 登录页面和脚本来从 fire-base 数据库对其进行身份验证。请提供解决方案代码或我的代码有什么问题或其中缺少某些内容。

 <!DOCTYPE html>
<html>
<head>

<!-- /////////////////firebase method ///////////////////// -->
<title>
the login form
</title>

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

<script>
// Initialize Firebase
var config = {
apiKey: "AIzaSyBgFUWzUrmLXVuKtGtChe2I2zvf5sYga54",
authDomain: "skool-1083c.firebaseapp.com",
databaseURL: "https://skool-1083c.firebaseio.com",
projectId: "skool-1083c",
storageBucket: "skool-1083c.appspot.com",
messagingSenderId: "911580445409"
};
firebase.initializeApp(config);
</script>

</head>
<body>

<h1>Admin Login</h1>
<form class="form" action="new_blank">
<input type="text" placeholder="username" id="email"autofocus><br>
<input type="password" placeholder="pasword" id="password" ><br></br>
<input type="submit" value="login" id="sign-in">
<br>



</form>
<!-- ///////////////stylesheet///////////// -->


<script>
document.querySelector('#sign-in').addEventListener('click', function(e) {
e.preventDefault();
e.stopPropagation();
var email = document.querySelector('#email').value;
var password = document.querySelector('#password').value
var credential = firebase.auth.EmailAuthProvider.credential(email, password);

window.alert(credential);
var auth = firebase.auth();
var currentUser = auth.currentUser;

// Step 2
// Get a credential with firebase.auth.emailAuthProvider.credential(emailInput.value, passwordInput.value)
// If there is no current user, log in with auth.signInWithCredential(credential)
// If there is a current user an it's anonymous, atttempt to link the new user with firebase.auth().currentUser.link(credential)
// The user link will fail if the user has already been created, so catch the error and sign in.
});
</script>
</body>

</html>

最佳答案

如果您想在 Firebase 身份验证中使用电子邮件+密码登录用户,请按照文档 here 进行操作。从那里登录的示例是:

firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// ...
});

要检测用户何时登录,请遵循文档 here 。从那里:

firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
} else {
// No user is signed in.
}
});

关于javascript - 如何使用android firebase数据库将firebase集成到webapp中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48721709/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com