I have a HTML page that includes JavaScript and CSS, but I want to host it on Firebase with separate files for JavaScript and CSS. While I understand how to do this locally, I'm unsure about the process when using Firebase.
P.S: Although I have experience with HTML, CSS, and JavaScript, my knowledge of Firebase is limited.
Code:
<!DOCTYPE html>
<html>
<head>
<title>noname</title>
<style type="text/css">
input{
resize: none;
border-radius: 5px;
size: 50px;
height: 100%;
}
#main{
text-align: center;
padding: 20px;
border: 5px solid;
width: 50%;
background-color: #c2e5ef;
background-clip: border-box;
}
.button{
color: #fff;
background-color: #3fb2bf;
margin: 10px 2px;
border: none;
font-size: 20px;
width: 100px;
height: 50px;
border-radius: 15px
}
#login-div{
text-align: center;
}
#logout-div{
text-align: center;
}
</style>
</head>
<body>
<div id="main">
<div id="login-div">
<label><b style="font-size: 20px;">Username:<input type="text" name="username" id="username" placeholder="Enter Username"><br>
</label>
<br>
<label>Password:<input type="text" name="password" id="password" placeholder="Enter Password"></label><br>
<input type="button" name="login" value="Login" class="button" onclick="login()">
</div>
<div id="logout-div">
<p>you are logged in</p>
<input type="button" name="logout" value="Logout" class="button" onclick="logout()">
</div>
<script src="https://www.gstatic.com/firebasejs/4.9.0/firebase.js"></script>
<script type="text/javascript">
var config = {
apiKey: "AIzaSyDf4ndBB-CXJwaYVLXXQacFmX3O9eZbUZk",
authDomain: "first-b14b2.firebaseapp.com",
databaseURL: "https://first-b14b2.firebaseio.com",
projectId: "first-b14b2",
storageBucket: "first-b14b2.appspot.com",
messagingSenderId: "103220354303"
};
firebase.initializeApp(config);
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
document.getElementById("login-div").style.display="none";
document.getElementById("logout-div").style.display="block";
} else {
document.getElementById("login-div").style.display="block";
document.getElementById("logout-div").style.display="none";
}
});
function login(){
var email=document.getElementById("username").value;
var pass=document.getElementById("password").value;
firebase.auth().signInWithEmailAndPassword(email, pass).catch(function(error) {
var errorCode = error.code;
var errorMessage = error.message;
window.alert("error");
});
}
function logout(){
firebase.auth().signOut().then(function() {
}).catch(function(error) {
});
}
</script>
</div>
</body>
</html>