JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<title>Authentication</title>
<script src="https://www.gstatic.com/firebasejs/4.12.1/firebase.js"></script>
</head>
<body id="index">
<input type="button" id="login" value="Login">
<input type="button" id="create" value="Criar: [email protected]">
<input type="button" id="update" value="Alterar senha">
<input type="button" id="delete" value="Excluir: [email protected]">
<input type="button" id="logout" value="Logout">
<hr />
<div id="console">
</div>
</body>
</html>
JavaScript
var config = {
apiKey: "AIzaSyCDbKd0lhysddQAIQx9_ooye2TvXyLQn0Q",
authDomain: "test-d7e7f.firebaseapp.com",
databaseURL: "https://test-d7e7f.firebaseio.com",
projectId: "test-d7e7f",
storageBucket: "test-d7e7f.appspot.com",
messagingSenderId: "466448961658"
};
firebase.initializeApp(config);
//escutando status do firebase
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
//online
document.getElementById("console").innerHTML = JSON.stringify( user );
} else {
document.getElementById("console").innerHTML = 'OffLine!';
}
});
//Ação de Login do botão #login
document.getElementById("login").onclick = function() {
firebase.auth().signInWithEmailAndPassword('[email protected]', '123mudar').catch(function(error) {
document.getElementById("console").innerHTML = JSON.stringify( error );
});
};
//Ação de Login do botão #logout
document.getElementById("logout").onclick = function() {
firebase.auth().signOut()
.then(function() {
document.getElementById("console").innerHTML = 'Logout';
}, function(error) {
document.getElementById("console").innerHTML = JSON.stringify( error );
});
};
//Ação de alterar senha do botão #update
document.getElementById("update").onclick = function() {
firebase.auth().currentUser.updatePassword('123mudar')
.then(function() {
document.getElementById("console").innerHTML = 'Senha Alterada!';
})
.catch(function(error) {
document.getElementById("console").innerHTML = JSON.stringify( error );
});
};
//Ação de criar do botão #create
document.getElementById("create").onclick = function() {
firebase.auth().createUserWithEmailAndPassword('[email protected]', "123mudar").catch(function(error) {
document.getElementById("console").innerHTML = JSON.stringify( error );
});
};
//Ação de excluir do botão #delete
document.getElementById("delete").onclick = function() {
var user = firebase.auth().currentUser;
user.delete().then(function() {
// User...