Spaces:
Paused
Paused
File size: 1,767 Bytes
65479e5 |
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 58 59 |
import {
initializeApp
} from "https://www.gstatic.com/firebasejs/11.6.1/firebase-app.js";
import {
getAuth,
onAuthStateChanged,
signOut,
signInAnonymously,
GoogleAuthProvider,
signInWithPopup
} from "https://www.gstatic.com/firebasejs/11.6.1/firebase-auth.js";
const firebaseConfig = {
apiKey: import.meta.env.FIREBASE_API_KEY,
authDomain: import.meta.env.FIREBASE_AUTH_DOMAIN,
projectId: import.meta.env.FIREBASE_PROJECT_ID,
storageBucket: import.meta.env.FIREBASE_STORAGE_BUCKET,
messagingSenderId: import.meta.env.FIREBASE_MESSAGING_SENDER_ID,
appId: import.meta.env.FIREBASE_APP_ID,
measurementId: import.meta.env.FIREBASE_MEASUREMENT_ID
};
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
const loginBtn = document.getElementById("loginAnonButton");
const logoutBtn = document.getElementById("logoutButton");
loginBtn.addEventListener("click", async () => {
try {
const provider = new GoogleAuthProvider();
await signInWithPopup(auth, provider);
} catch (err) {
console.error("Error al iniciar sesión:", err);
}
});
document.getElementById("anonymousLoginButton").addEventListener("click", async () => {
try {
await signInAnonymously(auth);
} catch (error) {
console.error(error);
}
});
logoutBtn.addEventListener("click", async () => {
await signOut(auth);
});
onAuthStateChanged(auth, (user) => {
if (user) {
document.getElementById("loginAnonButton").style.display = "none";
document.getElementById("logoutButton").style.display = "block";
} else {
document.getElementById("loginAnonButton").style.display = "block";
document.getElementById("logoutButton").style.display = "none";
}
});
|