-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.html
81 lines (74 loc) · 3.47 KB
/
signup.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Signup Page</title>
<link rel="stylesheet" href="style1.css">
</head>
<body>
<div class="signup-container">
<h2 class="green-text">Signup</h2>
<p id="signup-error" class="error-message"></p>
<form id="signup-form">
<div class="input-group">
<label for="signup-fullname">Full Name</label>
<input type="text" id="signup-fullname" name="signup-fullname" required />
</div>
<div class="input-group">
<label for="signup-email">Email</label>
<input type="email" id="signup-email" name="signup-email" required />
</div>
<div class="input-group">
<label for="signup-password">Password</label>
<input type="password" id="signup-password" name="signup-password" required />
</div>
<button type="submit">Signup</button>
</form>
<p class="green-text">Already have an account? <a href="./login.html">Login</a></p>
</div>
<!-- Load Firebase SDK -->
<script src="https://www.gstatic.com/firebasejs/10.11.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.11.1/firebase-auth.js"></script>
<script>
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyBwu3KyewvOeepKcmCSZkdbkAZjqSg4poE",
authDomain: "balancebudd-c5789.firebaseapp.com",
projectId: "balancebudd-c5789",
storageBucket: "balancebudd-c5789.appspot.com",
messagingSenderId: "187850436843",
appId: "1:187850436843:web:91af7c5b3c4eafbbfbceae",
measurementId: "G-NF6L3ETRVR"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
// Initialize Firebase Authentication
const auth = firebase.auth();
// Signup form submission event listener
document.getElementById('signup-form').addEventListener('submit', function(event) {
event.preventDefault(); // Prevent default form submission
// Get full name, email, and password from form inputs
const fullname = document.getElementById('signup-fullname').value;
const email = document.getElementById('signup-email').value;
const password = document.getElementById('signup-password').value;
// Create user with email and password using Firebase Authentication
auth.createUserWithEmailAndPassword(email, password)
.then((userCredential) => {
// User signed up successfully
const user = userCredential.user;
console.log('User signed up:', user);
// Redirect user to dashboard or desired page upon successful signup
window.location.href = 'index.html'; // Change to appropriate URL
})
.catch((error) => {
// Handle signup errors
const errorMessage = error.message;
console.error('Signup failed:', errorMessage);
// Display error message to the user (e.g., show it on the signup form)
document.getElementById('signup-error').innerText = errorMessage;
});
});
</script>
</body>
</html>