-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
105 lines (90 loc) · 3.61 KB
/
scripts.js
File metadata and controls
105 lines (90 loc) · 3.61 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
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.10/firebase-app.js";
import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.6.10/firebase-analytics.js";
import { getAuth, signInWithEmailAndPassword, createUserWithEmailAndPassword } from "https://www.gstatic.com/firebasejs/9.6.10/firebase-auth.js";
const firebaseConfig = {
apiKey: "AIzaSyDYcoC9heDYglnJ1npMYZRhQcmo_PE6Awk",
authDomain: "html-css-pwa.firebaseapp.com",
databaseURL: "https://html-css-pwa.firebaseio.com",
projectId: "html-css-pwa",
storageBucket: "html-css-pwa.firebasestorage.app",
messagingSenderId: "583323605721",
appId: "1:583323605721:web:c0935a4a2b4e5f3c"
};
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
const auth = getAuth(app);
const submitButton = document.getElementById("submit");
const signupButton = document.getElementById("sign-up");
const emailInput = document.getElementById("email");
const passwordInput = document.getElementById("password");
const main = document.getElementById("main");
const createacct = document.getElementById("create-acct")
const signupEmailIn = document.getElementById("email-signup");
const confirmSignupEmailIn = document.getElementById("confirm-email-signup");
const signupPasswordIn = document.getElementById("password-signup");
const confirmSignUpPasswordIn = document.getElementById("confirm-password-signup");
const createacctbtn = document.getElementById("create-acct-btn");
const returnBtn = document.getElementById("return-btn");
var email, password, signupEmail, signupPassword, confirmSignupEmail, confirmSignUpPassword;
createacctbtn.addEventListener("click", function() {
var isVerified = true;
signupEmail = signupEmailIn.value;
confirmSignupEmail = confirmSignupEmailIn.value;
if(signupEmail != confirmSignupEmail) {
window.alert("Email fields do not match. Try again.")
isVerified = false;
}
signupPassword = signupPasswordIn.value;
confirmSignUpPassword = confirmSignUpPasswordIn.value;
if(signupPassword != confirmSignUpPassword) {
window.alert("Password fields do not match. Try again.")
isVerified = false;
}
if(signupEmail == null || confirmSignupEmail == null || signupPassword == null || confirmSignUpPassword == null) {
window.alert("Please fill out all required fields.");
isVerified = false;
}
if(isVerified) {
createUserWithEmailAndPassword(auth, signupEmail, signupPassword)
.then((userCredential) => {
// Signed in
const user = userCredential.user;
// ...
window.alert("Success! Account created.");
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
// ..
window.alert("Error occurred. Try again.");
});
}
});
submitButton.addEventListener("click", function() {
email = emailInput.value;
console.log(email);
password = passwordInput.value;
console.log(password);
signInWithEmailAndPassword(auth, email, password)
.then((userCredential) => {
// Signed in
const user = userCredential.user;
console.log("Success! Welcome back!");
window.alert("Success! Welcome back!");
// ...
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
console.log("Error occurred. Try again.");
window.alert("Error occurred. Try again.");
});
});
signupButton.addEventListener("click", function() {
main.style.display = "none";
createacct.style.display = "block";
});
returnBtn.addEventListener("click", function() {
main.style.display = "block";
createacct.style.display = "none";
});