Spaces:
Running
Running
Update index.html
Browse files- index.html +48 -8
index.html
CHANGED
|
@@ -267,6 +267,8 @@
|
|
| 267 |
signInWithPopup,
|
| 268 |
signInWithRedirect,
|
| 269 |
getRedirectResult,
|
|
|
|
|
|
|
| 270 |
signOut
|
| 271 |
} from "https://www.gstatic.com/firebasejs/11.6.1/firebase-auth.js";
|
| 272 |
import {
|
|
@@ -456,16 +458,26 @@
|
|
| 456 |
? browserLocalPersistence
|
| 457 |
: browserSessionPersistence;
|
| 458 |
await setPersistence(auth, persistence);
|
|
|
|
| 459 |
// En Hugging Face (Static) forzamos redirect para evitar bloqueos/doble popup
|
| 460 |
if (isHFStatic) {
|
| 461 |
if (loginMessage) {
|
| 462 |
loginMessage.innerText = 'Redirigiendo a Google...';
|
| 463 |
}
|
| 464 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 465 |
return;
|
| 466 |
}
|
| 467 |
|
| 468 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 469 |
} catch (error) {
|
| 470 |
console.warn("Google Sign-In con popup falló:", error?.code, error?.message);
|
| 471 |
// Solo si el problema es popup bloqueado, hacemos redirect (evita doble popup)
|
|
@@ -477,11 +489,30 @@
|
|
| 477 |
}
|
| 478 |
const provider = new GoogleAuthProvider();
|
| 479 |
provider.setCustomParameters({ prompt: 'select_account' });
|
| 480 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 481 |
return;
|
| 482 |
} catch (redirectErr) {
|
| 483 |
console.error("Error en signInWithRedirect:", redirectErr);
|
| 484 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 485 |
} else if (error?.code !== 'auth/popup-closed-by-user') {
|
| 486 |
// Si el usuario cerró el popup, no mostrar error intrusivo
|
| 487 |
console.error("Error con Google Sign-In:", error);
|
|
@@ -526,11 +557,16 @@
|
|
| 526 |
}
|
| 527 |
});
|
| 528 |
|
| 529 |
-
// Procesar posible resultado de Google Sign-In via redirect
|
| 530 |
try {
|
| 531 |
const redirectResult = await getRedirectResult(auth);
|
| 532 |
if (redirectResult && redirectResult.user) {
|
| 533 |
-
console.log('
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 534 |
}
|
| 535 |
} catch (redirectCheckErr) {
|
| 536 |
console.warn('Error al obtener resultado de redirect de Google:', redirectCheckErr);
|
|
@@ -580,9 +616,13 @@
|
|
| 580 |
mainLogoutButton.style.display = 'inline-block';
|
| 581 |
tryStartApp();
|
| 582 |
}
|
| 583 |
-
//
|
| 584 |
-
|
| 585 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 586 |
} else {
|
| 587 |
console.log("Ningún usuario autenticado.");
|
| 588 |
userId = null;
|
|
|
|
| 267 |
signInWithPopup,
|
| 268 |
signInWithRedirect,
|
| 269 |
getRedirectResult,
|
| 270 |
+
linkWithPopup,
|
| 271 |
+
linkWithRedirect,
|
| 272 |
signOut
|
| 273 |
} from "https://www.gstatic.com/firebasejs/11.6.1/firebase-auth.js";
|
| 274 |
import {
|
|
|
|
| 458 |
? browserLocalPersistence
|
| 459 |
: browserSessionPersistence;
|
| 460 |
await setPersistence(auth, persistence);
|
| 461 |
+
const upgradingAnonymous = auth.currentUser && auth.currentUser.isAnonymous;
|
| 462 |
// En Hugging Face (Static) forzamos redirect para evitar bloqueos/doble popup
|
| 463 |
if (isHFStatic) {
|
| 464 |
if (loginMessage) {
|
| 465 |
loginMessage.innerText = 'Redirigiendo a Google...';
|
| 466 |
}
|
| 467 |
+
if (upgradingAnonymous) {
|
| 468 |
+
// Vincular Google a la sesión anónima existente
|
| 469 |
+
await linkWithRedirect(auth.currentUser, provider);
|
| 470 |
+
} else {
|
| 471 |
+
await signInWithRedirect(auth, provider);
|
| 472 |
+
}
|
| 473 |
return;
|
| 474 |
}
|
| 475 |
|
| 476 |
+
if (upgradingAnonymous) {
|
| 477 |
+
await linkWithPopup(auth.currentUser, provider);
|
| 478 |
+
} else {
|
| 479 |
+
await signInWithPopup(auth, provider);
|
| 480 |
+
}
|
| 481 |
} catch (error) {
|
| 482 |
console.warn("Google Sign-In con popup falló:", error?.code, error?.message);
|
| 483 |
// Solo si el problema es popup bloqueado, hacemos redirect (evita doble popup)
|
|
|
|
| 489 |
}
|
| 490 |
const provider = new GoogleAuthProvider();
|
| 491 |
provider.setCustomParameters({ prompt: 'select_account' });
|
| 492 |
+
const upgradingAnonymous = auth.currentUser && auth.currentUser.isAnonymous;
|
| 493 |
+
if (upgradingAnonymous) {
|
| 494 |
+
await linkWithRedirect(auth.currentUser, provider);
|
| 495 |
+
} else {
|
| 496 |
+
await signInWithRedirect(auth, provider);
|
| 497 |
+
}
|
| 498 |
return;
|
| 499 |
} catch (redirectErr) {
|
| 500 |
console.error("Error en signInWithRedirect:", redirectErr);
|
| 501 |
}
|
| 502 |
+
} else if (error?.code === 'auth/credential-already-in-use' || error?.code === 'auth/account-exists-with-different-credential') {
|
| 503 |
+
// Si ya existe la cuenta con otras credenciales, intentar un signIn normal por redirect
|
| 504 |
+
try {
|
| 505 |
+
const provider = new GoogleAuthProvider();
|
| 506 |
+
provider.setCustomParameters({ prompt: 'select_account' });
|
| 507 |
+
if (isHFStatic) {
|
| 508 |
+
await signInWithRedirect(auth, provider);
|
| 509 |
+
return;
|
| 510 |
+
} else {
|
| 511 |
+
await signInWithPopup(auth, provider);
|
| 512 |
+
}
|
| 513 |
+
} catch (e2) {
|
| 514 |
+
console.error('Error al recuperar cuenta existente con Google:', e2);
|
| 515 |
+
}
|
| 516 |
} else if (error?.code !== 'auth/popup-closed-by-user') {
|
| 517 |
// Si el usuario cerró el popup, no mostrar error intrusivo
|
| 518 |
console.error("Error con Google Sign-In:", error);
|
|
|
|
| 557 |
}
|
| 558 |
});
|
| 559 |
|
| 560 |
+
// Procesar posible resultado de Google Sign-In / Link via redirect
|
| 561 |
try {
|
| 562 |
const redirectResult = await getRedirectResult(auth);
|
| 563 |
if (redirectResult && redirectResult.user) {
|
| 564 |
+
console.log('Redirect completado. Usuario:', redirectResult.user.uid);
|
| 565 |
+
// onAuthStateChanged gestionará el resto (UI, escena, etc.)
|
| 566 |
+
if (loginMessage) {
|
| 567 |
+
loginMessage.innerText = 'Autenticación completada.';
|
| 568 |
+
loginMessage.classList.remove('text-red-500');
|
| 569 |
+
}
|
| 570 |
}
|
| 571 |
} catch (redirectCheckErr) {
|
| 572 |
console.warn('Error al obtener resultado de redirect de Google:', redirectCheckErr);
|
|
|
|
| 616 |
mainLogoutButton.style.display = 'inline-block';
|
| 617 |
tryStartApp();
|
| 618 |
}
|
| 619 |
+
// Ocultar overlay solo si el usuario ya puede entrar al app
|
| 620 |
+
// (anónimo o con perfil existente). Si no hay perfil, tryStartApp
|
| 621 |
+
// mostrará el formulario de username y mantendrá el overlay visible.
|
| 622 |
+
if (user.isAnonymous || userProfile) {
|
| 623 |
+
loginOverlay.style.opacity = '0';
|
| 624 |
+
setTimeout(() => { loginOverlay.style.display = 'none'; }, 500);
|
| 625 |
+
}
|
| 626 |
} else {
|
| 627 |
console.log("Ningún usuario autenticado.");
|
| 628 |
userId = null;
|