似乎我无法登录Firebase上的帐户。
老实说,我不知道该怎么做。我不知所措,因为我刚接触Firebase。
以下是登录代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Log in</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form onsubmit="signin()">
<input id="email" type="email" name="email">
<input id="password" type="password" name="password">
<input type="submit" Value="Log in">
</form>
<script src="https://www.gstatic.com/firebasejs/5.8.2/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "api key",
authDomain: "domain",
databaseURL: "databaseurl",
projectId: "id",
storageBucket: "bucket",
messagingSenderId: "senderid"
};
firebase.initializeApp(config);
function signin() {
var email = document.getElementById('email').value;
var password = document.getElementById('password').value;
firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// ...
});
}
</script>
</body>
</html>
然后是帐户页面的代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>repl.it</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1 id="useremail"></h1>
<script src="https://www.gstatic.com/firebasejs/5.8.2/firebase.js"></script>
<script>
var config = {
apiKey: "api key",
authDomain: "domain",
databaseURL: "databaseurl",
projectId: "id",
storageBucket: "bucket",
messagingSenderId: "senderid"
};
firebase.initializeApp(config);
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
document.getElementById("useremail").innerHTML = "Logged in";
} else {
// No user is signed in.
document.getElementById("useremail").innerHTML = "Not logged in";
}
});
</script>
</body>
</html>
如果您已登录帐户,则帐户页面应显示“已登录”,但提示未登录,即使我相信我已使用登录页面登录了该帐户。
网站网址:https://calculatingclutteredgreenware--mrsprinkletoes.repl.co/