-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (39 loc) · 1.22 KB
/
index.js
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
// Import the functions you need from the SDKs you need
import { getFirestore } from "https://www.gstatic.com/firebasejs/9.6.0/firebase-firestore.js";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
apiKey: "<api key>",
authDomain: "<auth domain>",
projectId: "<>",
storageBucket: "<>",
messagingSenderId: "<>",
appId: "<>",
measurementId: "<>",
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
const db = firebase.firestore();
//create a form submit function and log user to firestore
function submitForm() {
const email = document.getElementById("email").value;
const password = document.getElementById("password").value;
const user = {
email: email,
password: password,
};
db.collection("users")
.add(user)
.then((res) => {
alert("Logged in successfully");
})
.catch((err) => {
alert(err);
});
}
document.getElementById("form").addEventListener("submit", (event) => {
event.preventDefault();
submitForm();
});