Skip to content

Commit 457541d

Browse files
Update gpt.html
1 parent c19b432 commit 457541d

File tree

1 file changed

+47
-41
lines changed

1 file changed

+47
-41
lines changed

gpt.html

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,47 +8,47 @@
88
<script src="https://www.gstatic.com/firebasejs/10.7.1/firebase-analytics.js"></script>
99
<script src="https://www.gstatic.com/firebasejs/10.7.1/firebase-auth.js"></script>
1010
<script>
11-
// Your web app's Firebase configuration
12-
const firebaseConfig = {
13-
apiKey: "AIzaSyBH3LvyIKTVeEZ4KYFbxFAWumn2B9GtzTE",
14-
authDomain: "cmepass-391c3.firebaseapp.com",
15-
projectId: "cmepass-391c3",
16-
storageBucket: "cmepass-391c3.appspot.com",
17-
messagingSenderId: "495360510420",
18-
appId: "1:495360510420:web:338107bc68b5f0bb7e2e41",
19-
measurementId: "G-DL15HN05NG"
20-
};
11+
document.addEventListener('DOMContentLoaded', function() {
12+
// Your web app's Firebase configuration
13+
const firebaseConfig = {
14+
apiKey: "AIzaSyBH3LvyIKTVeEZ4KYFbxFAWumn2B9GtzTE",
15+
authDomain: "cmepass-391c3.firebaseapp.com",
16+
projectId: "cmepass-391c3",
17+
storageBucket: "cmepass-391c3.appspot.com",
18+
messagingSenderId: "495360510420",
19+
appId: "1:495360510420:web:338107bc68b5f0bb7e2e41",
20+
measurementId: "G-DL15HN05NG"
21+
};
2122

22-
// Initialize Firebase
23-
firebase.initializeApp(firebaseConfig);
24-
firebase.analytics();
25-
const auth = firebase.auth();
23+
// Initialize Firebase
24+
firebase.initializeApp(firebaseConfig);
25+
firebase.analytics();
26+
const auth = firebase.auth();
2627

27-
// Sign in function
28-
function signIn() {
29-
var email = document.getElementById('email').value;
30-
var password = document.getElementById('password').value;
31-
auth.signInWithEmailAndPassword(email, password)
32-
.then((userCredential) => {
33-
// Signed in
34-
document.getElementById('status').innerText = 'Logged in successfully. Welcome, ' + userCredential.user.email;
35-
})
36-
.catch((error) => {
37-
var errorCode = error.code;
38-
var errorMessage = error.message;
39-
document.getElementById('status').innerText = 'Error: ' + errorMessage;
40-
});
41-
}
28+
// Handle form submission
29+
document.getElementById('login-form').addEventListener('submit', function(e) {
30+
e.preventDefault();
31+
var email = document.getElementById('email').value;
32+
var password = document.getElementById('password').value;
33+
auth.signInWithEmailAndPassword(email, password)
34+
.then((userCredential) => {
35+
document.getElementById('status').innerText = 'Logged in successfully. Welcome, ' + userCredential.user.email;
36+
})
37+
.catch((error) => {
38+
var errorCode = error.code;
39+
var errorMessage = error.message;
40+
document.getElementById('status').innerText = 'Error: ' + errorMessage;
41+
});
42+
});
4243

43-
// Auth state changes
44-
auth.onAuthStateChanged((user) => {
45-
if (user) {
46-
// User is signed in
47-
document.getElementById('status').innerText = 'User is currently signed in';
48-
} else {
49-
// User is signed out
50-
document.getElementById('status').innerText = 'User is signed out';
51-
}
44+
// Auth state changes
45+
auth.onAuthStateChanged((user) => {
46+
if (user) {
47+
document.getElementById('status').innerText = 'User is currently signed in';
48+
} else {
49+
document.getElementById('status').innerText = 'User is signed out';
50+
}
51+
});
5252
});
5353
</script>
5454
<style>
@@ -81,13 +81,19 @@
8181
margin-top: 20px;
8282
color: #d9534f;
8383
}
84+
form {
85+
display: inline-block;
86+
text-align: left;
87+
}
8488
</style>
8589
</head>
8690
<body>
8791
<h1>Firebase Authentication Example</h1>
88-
<input type="email" id="email" placeholder="Email">
89-
<input type="password" id="password" placeholder="Password">
90-
<button onclick="signIn()">Sign In</button>
92+
<form id="login-form">
93+
<input type="email" id="email" placeholder="Email">
94+
<input type="password" id="password" placeholder="Password">
95+
<button type="submit">Sign In</button>
96+
</form>
9197
<div id="status"></div>
9298
</body>
9399
</html>

0 commit comments

Comments
 (0)