-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
69 lines (62 loc) · 2.46 KB
/
app.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.18.0/firebase-app.js";
import { getAuth, createUserWithEmailAndPassword, } from "https://www.gstatic.com/firebasejs/9.18.0/firebase-auth.js";
import { getDatabase, ref, set, child, update, remove } from "https://www.gstatic.com/firebasejs/9.18.0/firebase-database.js";
// import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.18.0/firebase-analytics.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: "AIzaSyCe3PV094-Qyp972MFiARTCQxSbLZ_gw1o",
authDomain: "mentalhealth-52558.firebaseapp.com",
projectId: "mentalhealth-52558",
storageBucket: "mentalhealth-52558.appspot.com",
messagingSenderId: "199609149416",
appId: "1:199609149416:web:5dd447516532b7abdf265d",
measurementId: "G-BY972TXWWL"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const db = getDatabase();
// const analytics = getAnalytics(app);
const auth = getAuth();
// Getting all the elements of html
var name = document.getElementById("name");
var email = document.getElementById("email");
var password = document.getElementById("password");
var confirmPassword = document.getElementById("confirm-password");
// making a function for storing user data
function InsertData() {
set(ref(db, "Users/" + name.value), {
name: name.value,
email: email.value,
password: password.value,
})
.then(() => {
console.log("Data saved successfully");
})
.catch((error) => {
console.log("data save error" + error);
});
}
// function for creating a user on Firebase authentication and storing user data in Firebase Realtime Database
window.signUp = function(e) {
e.preventDefault();
var obj = {
name:name.value,
email:email.value,
password:password.value,
}
createUserWithEmailAndPassword(auth,obj.email,obj.password)
.then(function(success) {
InsertData();
alert("You have Signed Up Successfully")
window.location.replace('signIn.html')
})
.catch(function(err) {
alert("error" + err)
})
console.log(obj)
};
document.getElementById('SignUpForm').addEventListener('submit', InsertData);