Spaces:
Paused
Paused
| 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"; | |
| } | |
| }); | |