Skip to content

Commit 0637090

Browse files
authored
Create login.html (#136)
* Create login.html Signed-off-by: Grouvex <168425996+Grouvex@users.noreply.github.com> * Update footer.html Signed-off-by: Grouvex <168425996+Grouvex@users.noreply.github.com> --------- Signed-off-by: Grouvex <168425996+Grouvex@users.noreply.github.com>
1 parent 319e84f commit 0637090

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

footer.html

+23
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,29 @@
3030
}
3131
</style>
3232
<footer>
33+
<button id="logoutBtn">Logout</button>
34+
<script>
35+
document.getElementById('logoutBtn').addEventListener('click', () => {
36+
firebase.auth().signOut().then(() => {
37+
console.log('User logged out');
38+
}).catch((error) => {
39+
console.error('Error logging out:', error);
40+
});
41+
});
42+
</script>
43+
<script>
44+
function protegerRuta() {
45+
firebase.auth().onAuthStateChanged((user) => {
46+
if (!user) {
47+
// Redireccionar a la página de inicio de sesión si no está autenticado
48+
window.location.href = 'login.html';
49+
}
50+
});
51+
}
52+
53+
// Llamar a la función de protección de ruta en las páginas que necesiten protección
54+
protegerRuta();
55+
</script>
3356
<div class="footer-imagenes">
3457
<a href="https://instagram.com/grouvex" target="_blank"><img src="https://grouvex.github.io/img/Instagram.png" alt=""></a>
3558
<a href="https://youtube.com/@Grouvex" target="_blank"><img src="https://grouvex.github.io/img/YouTube.png" alt=""></a>

login.html

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<form id="loginForm">
2+
<input type="email" id="loginEmail" placeholder="Email" required>
3+
<input type="password" id="loginPassword" placeholder="Password" required>
4+
<button type="submit">Login</button>
5+
</form>
6+
<a src="#">#</a>
7+
<script>
8+
document.getElementById('loginForm').addEventListener('submit', (e) => {
9+
e.preventDefault();
10+
const email = document.getElementById('loginEmail').value;
11+
const password = document.getElementById('loginPassword').value;
12+
13+
firebase.auth().signInWithEmailAndPassword(email, password)
14+
.then((userCredential) => {
15+
// Usuario inició sesión
16+
console.log('User logged in:', userCredential.user);
17+
})
18+
.catch((error) => {
19+
console.error('Error logging in user:', error);
20+
});
21+
});
22+
</script>

0 commit comments

Comments
 (0)