ameenmarashi commited on
Commit
ea60cd2
·
verified ·
1 Parent(s): 8f790a7

Update app.js

Browse files
Files changed (1) hide show
  1. app.js +37 -1
app.js CHANGED
@@ -1,6 +1,7 @@
 
1
  document.getElementById('googleSignUp').addEventListener('click', function() {
2
  var provider = new firebase.auth.GoogleAuthProvider();
3
-
4
  firebase.auth().signInWithPopup(provider)
5
  .then((result) => {
6
  // This gives you a Google Access Token. You can use it to access the Google API.
@@ -15,12 +16,47 @@ document.getElementById('googleSignUp').addEventListener('click', function() {
15
  var errorMessage = error.message;
16
  var email = error.email;
17
  var credential = error.credential;
 
 
 
 
 
 
18
  if (errorCode === 'auth/popup-closed-by-user') {
19
  console.error('Error: The popup has been closed by the user before finalizing the operation.');
20
  alert('The sign-up popup was closed before completing the sign-up. Please try again.');
 
 
 
 
 
 
21
  } else {
22
  console.error('Error during sign up:', error);
23
  alert(`Error: ${errorMessage}`);
24
  }
25
  });
26
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Initialize Firebase
2
  document.getElementById('googleSignUp').addEventListener('click', function() {
3
  var provider = new firebase.auth.GoogleAuthProvider();
4
+
5
  firebase.auth().signInWithPopup(provider)
6
  .then((result) => {
7
  // This gives you a Google Access Token. You can use it to access the Google API.
 
16
  var errorMessage = error.message;
17
  var email = error.email;
18
  var credential = error.credential;
19
+
20
+ console.error('Error Code:', errorCode);
21
+ console.error('Error Message:', errorMessage);
22
+ console.error('Error Email:', email);
23
+ console.error('Error Credential:', credential);
24
+
25
  if (errorCode === 'auth/popup-closed-by-user') {
26
  console.error('Error: The popup has been closed by the user before finalizing the operation.');
27
  alert('The sign-up popup was closed before completing the sign-up. Please try again.');
28
+ } else if (errorCode === 'auth/cancelled-popup-request') {
29
+ console.error('Error: Only one popup request is allowed at one time.');
30
+ alert('Multiple popup requests are not allowed. Please try again.');
31
+ } else if (errorCode === 'auth/popup-blocked') {
32
+ console.error('Error: The popup was blocked by the browser.');
33
+ alert('The sign-up popup was blocked by the browser. Please allow popups and try again.');
34
  } else {
35
  console.error('Error during sign up:', error);
36
  alert(`Error: ${errorMessage}`);
37
  }
38
  });
39
  });
40
+
41
+ // Handle Email/Password Registration
42
+ document.getElementById('registerForm').addEventListener('submit', function(event) {
43
+ event.preventDefault(); // Prevent form from submitting the default way
44
+
45
+ var email = document.getElementById('email').value;
46
+ var password = document.getElementById('password').value;
47
+
48
+ firebase.auth().createUserWithEmailAndPassword(email, password)
49
+ .then((userCredential) => {
50
+ // Signed in
51
+ var user = userCredential.user;
52
+ console.log('User Info:', user);
53
+ alert(`Hello, ${user.email}! You've successfully registered.`);
54
+ })
55
+ .catch((error) => {
56
+ var errorCode = error.code;
57
+ var errorMessage = error.message;
58
+ console.error('Error Code:', errorCode);
59
+ console.error('Error Message:', errorMessage);
60
+ alert(`Error: ${errorMessage}`);
61
+ });
62
+ });