-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwelcome.js
29 lines (22 loc) · 950 Bytes
/
welcome.js
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
import { auth } from './firebase.js';
import { onAuthStateChanged, signOut } from "https://www.gstatic.com/firebasejs/10.12.4/firebase-auth.js";
document.addEventListener('DOMContentLoaded', () => {
const emailElement = document.querySelector('email-id');
const logoutButton = document.querySelector('.btn-danger');
onAuthStateChanged(auth, (user) => {
if (user) {
// User is signed in
emailElement.textContent = user.email;
} else {
// User is signed out, redirect to login page
window.location.href = 'index.html';
}
});
logoutButton.addEventListener('click', () => {
signOut(auth).then(() => {
window.location.href = 'index.html'; // Redirect to login page after logout
}).catch((error) => {
console.error('Sign out error:', error);
});
});
});