-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdashboard.js
More file actions
57 lines (51 loc) · 1.68 KB
/
dashboard.js
File metadata and controls
57 lines (51 loc) · 1.68 KB
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
// Firebase Imports
import { initializeApp } from "https://www.gstatic.com/firebasejs/12.6.0/firebase-app.js";
import {
getAuth,
onAuthStateChanged,
signOut
} from "https://www.gstatic.com/firebasejs/12.6.0/firebase-auth.js";
// Your Firebase Config
const firebaseConfig = {
apiKey: "AIzaSyBYrk0pA2n36c-fk9NvpwJYw2mcTBYsAnc",
authDomain: "maxima-6f4dc.firebaseapp.com",
projectId: "maxima-6f4dc",
storageBucket: "maxima-6f4dc.firebasestorage.app",
messagingSenderId: "294387008300",
appId: "1:294387008300:web:6b276d0689742576432289",
measurementId: "G-D6W9MKN7PD"
};
// Init App + Auth
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
// DOM Elements
const emailElement = document.getElementById("email");
const userIdElement = document.getElementById("userid");
const profilePicElement = document.getElementById("profilePic");
// Detect user state
onAuthStateChanged(auth, (user) => {
if (user) {
// Show email + UID
emailElement.textContent = user.email;
userIdElement.textContent = user.uid;
// Profile picture (if exists)
if (user.photoURL) {
profilePicElement.src = user.photoURL;
} else {
profilePicElement.src = "/img/image.png"; // default pic
}
} else {
// If NOT logged in → redirect to login page
window.location.href = "login.html";
}
});
// LOGOUT BUTTON
document.getElementById("logoutBtn").addEventListener("click", () => {
signOut(auth)
.then(() => {
window.location.href = "login.html";
})
.catch((error) => {
alert("Logout failed: " + error.message);
});
});