|
4 | 4 | <meta charset="UTF-8">
|
5 | 5 | <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 | 6 | <title>Firebase Authentication Example</title>
|
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"; |
12 |
| - |
| 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> |
13 | 11 | // Your web app's Firebase configuration
|
14 | 12 | const firebaseConfig = {
|
15 | 13 | apiKey: "AIzaSyBH3LvyIKTVeEZ4KYFbxFAWumn2B9GtzTE",
|
|
22 | 20 | };
|
23 | 21 |
|
24 | 22 | // Initialize Firebase
|
25 |
| - const app = initializeApp(firebaseConfig); |
26 |
| - const analytics = getAnalytics(app); |
27 |
| - const auth = getAuth(app); |
| 23 | + firebase.initializeApp(firebaseConfig); |
| 24 | + firebase.analytics(); |
| 25 | + const auth = firebase.auth(); |
28 | 26 |
|
29 | 27 | // Sign in function
|
30 | 28 | function signIn() {
|
31 | 29 | var email = document.getElementById('email').value;
|
32 | 30 | var password = document.getElementById('password').value;
|
33 |
| - signInWithEmailAndPassword(auth, email, password) |
| 31 | + auth.signInWithEmailAndPassword(email, password) |
34 | 32 | .then((userCredential) => {
|
35 | 33 | // Signed in
|
36 | 34 | document.getElementById('status').innerText = 'Logged in successfully. Welcome, ' + userCredential.user.email;
|
|
43 | 41 | }
|
44 | 42 |
|
45 | 43 | // Auth state changes
|
46 |
| - onAuthStateChanged(auth, (user) => { |
| 44 | + auth.onAuthStateChanged((user) => { |
47 | 45 | if (user) {
|
48 | 46 | // User is signed in
|
49 | 47 | document.getElementById('status').innerText = 'User is currently signed in';
|
|
0 commit comments