Skip to content

Commit 7ef84a2

Browse files
Update gpt.html
1 parent 457541d commit 7ef84a2

File tree

1 file changed

+47
-51
lines changed

1 file changed

+47
-51
lines changed

gpt.html

Lines changed: 47 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,53 @@
44
<meta charset="UTF-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<title>Firebase Authentication Example</title>
7-
<script src="https://www.gstatic.com/firebasejs/10.7.1/firebase-app.js"></script>
8-
<script src="https://www.gstatic.com/firebasejs/10.7.1/firebase-analytics.js"></script>
9-
<script src="https://www.gstatic.com/firebasejs/10.7.1/firebase-auth.js"></script>
10-
<script>
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-
};
7+
<script type="module">
8+
// Import the functions you need from the SDKs you need
9+
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.7.1/firebase-app.js";
10+
import { getAnalytics } from "https://www.gstatic.com/firebasejs/10.7.1/firebase-analytics.js";
11+
import { getAuth, signInWithEmailAndPassword, onAuthStateChanged } from "https://www.gstatic.com/firebasejs/10.7.1/firebase-auth.js";
2212

23-
// Initialize Firebase
24-
firebase.initializeApp(firebaseConfig);
25-
firebase.analytics();
26-
const auth = firebase.auth();
13+
// Your web app's Firebase configuration
14+
const firebaseConfig = {
15+
apiKey: "AIzaSyBH3LvyIKTVeEZ4KYFbxFAWumn2B9GtzTE",
16+
authDomain: "cmepass-391c3.firebaseapp.com",
17+
projectId: "cmepass-391c3",
18+
storageBucket: "cmepass-391c3.appspot.com",
19+
messagingSenderId: "495360510420",
20+
appId: "1:495360510420:web:338107bc68b5f0bb7e2e41",
21+
measurementId: "G-DL15HN05NG"
22+
};
2723

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-
});
24+
// Initialize Firebase
25+
const app = initializeApp(firebaseConfig);
26+
const analytics = getAnalytics(app);
27+
const auth = getAuth(app);
4328

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-
});
29+
// Sign in function
30+
function signIn() {
31+
var email = document.getElementById('email').value;
32+
var password = document.getElementById('password').value;
33+
signInWithEmailAndPassword(auth, email, password)
34+
.then((userCredential) => {
35+
// Signed in
36+
document.getElementById('status').innerText = 'Logged in successfully. Welcome, ' + userCredential.user.email;
37+
})
38+
.catch((error) => {
39+
var errorCode = error.code;
40+
var errorMessage = error.message;
41+
document.getElementById('status').innerText = 'Error: ' + errorMessage;
42+
});
43+
}
44+
45+
// Auth state changes
46+
onAuthStateChanged(auth, (user) => {
47+
if (user) {
48+
// User is signed in
49+
document.getElementById('status').innerText = 'User is currently signed in';
50+
} else {
51+
// User is signed out
52+
document.getElementById('status').innerText = 'User is signed out';
53+
}
5254
});
5355
</script>
5456
<style>
@@ -81,19 +83,13 @@
8183
margin-top: 20px;
8284
color: #d9534f;
8385
}
84-
form {
85-
display: inline-block;
86-
text-align: left;
87-
}
8886
</style>
8987
</head>
9088
<body>
9189
<h1>Firebase Authentication Example</h1>
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>
90+
<input type="email" id="email" placeholder="Email">
91+
<input type="password" id="password" placeholder="Password">
92+
<button onclick="signIn()">Sign In</button>
9793
<div id="status"></div>
9894
</body>
9995
</html>

0 commit comments

Comments
 (0)