-
Notifications
You must be signed in to change notification settings - Fork 259
/
signupjs.js
65 lines (56 loc) · 2.16 KB
/
signupjs.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
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.11.1/firebase-app.js";
import { getAuth, GoogleAuthProvider, signInWithPopup } from "https://www.gstatic.com/firebasejs/10.11.1/firebase-auth.js";
const firebaseConfig = {
apiKey: "AIzaSyDx_FcoL3XJryt6BInhOaDsMKiSmxzrYBI",
authDomain: "fir-7f3dd.firebaseapp.com",
projectId: "fir-7f3dd",
storageBucket: "fir-7f3dd.appspot.com",
messagingSenderId: "467011865433",
appId: "1:467011865433:web:e23be9d0cc3496bb961a48"
};
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
auth.languageCode = 'en';
const provider = new GoogleAuthProvider();
document.getElementById("google").addEventListener("click", function() {
signInWithPopup(auth, provider)
.then((result) => {
const credential = GoogleAuthProvider.credentialFromResult(result);
const user = result.user;
console.log(user);
window.location.href = "./signedup.html";
}).catch((error) => {
console.error("Error during Google sign-in:", error);
});
});
document.getElementById("signup-form").addEventListener("submit", function(event) {
event.preventDefault(); // Prevent form from submitting the default way
const name = document.getElementById("name").value;
const email = document.getElementById("email").value;
const password = document.getElementById("password").value;
if (validateForm(name, email, password)) {
// Simulate a successful registration (Replace with actual Firebase sign-up logic)
console.log("Form submitted with:", { name, email, password });
window.location.href = "./signedup.html";
}
});
function validateForm(name, email, password) {
if (name === "" || email === "" || password === "") {
alert("All fields are required!");
return false;
}
if (!validateEmail(email)) {
alert("Please enter a valid email address.");
return false;
}
if (password.length < 6) {
alert("Password must be at least 6 characters long.");
return false;
}
return true;
}
function validateEmail(email) {
const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return re.test(email);
}
/*646664380070-n07i34glgcc6sanb59p3m1k5k0cgn1v1.apps.googleusercontent.com*/