Harshit Ghosh commited on
Commit ·
7ceec19
1
Parent(s): 353c165
Add iframe detection banner for third-party cookie blocking
Browse files- static/js/auth-shared.js +37 -14
static/js/auth-shared.js
CHANGED
|
@@ -3,12 +3,6 @@
|
|
| 3 |
* Provides: makePasswordToggle(), passwordStrengthMeter()
|
| 4 |
*/
|
| 5 |
|
| 6 |
-
/**
|
| 7 |
-
* Wire up a show/hide password toggle button.
|
| 8 |
-
* @param {string} btnId - ID of the toggle button
|
| 9 |
-
* @param {string} inputId - ID of the password input
|
| 10 |
-
* @param {string} iconId - ID of the SVG element inside the button
|
| 11 |
-
*/
|
| 12 |
function makePasswordToggle(btnId, inputId, iconId) {
|
| 13 |
const btn = document.getElementById(btnId);
|
| 14 |
const input = document.getElementById(inputId);
|
|
@@ -19,22 +13,14 @@ function makePasswordToggle(btnId, inputId, iconId) {
|
|
| 19 |
const isHidden = input.type === 'password';
|
| 20 |
input.type = isHidden ? 'text' : 'password';
|
| 21 |
icon.innerHTML = isHidden
|
| 22 |
-
/* eye-off */
|
| 23 |
? '<path d="M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94"/>' +
|
| 24 |
'<path d="M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19"/>' +
|
| 25 |
'<line x1="1" y1="1" x2="23" y2="23"/>'
|
| 26 |
-
/* eye */
|
| 27 |
: '<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/>' +
|
| 28 |
'<circle cx="12" cy="12" r="3"/>';
|
| 29 |
});
|
| 30 |
}
|
| 31 |
|
| 32 |
-
/**
|
| 33 |
-
* Wire up a live password-strength indicator.
|
| 34 |
-
* @param {string} inputId - ID of the password input
|
| 35 |
-
* @param {string} barId - ID of the strength fill div
|
| 36 |
-
* @param {string} textId - ID of the strength label span
|
| 37 |
-
*/
|
| 38 |
function passwordStrengthMeter(inputId, barId, textId) {
|
| 39 |
const input = document.getElementById(inputId);
|
| 40 |
const bar = document.getElementById(barId);
|
|
@@ -59,3 +45,40 @@ function passwordStrengthMeter(inputId, barId, textId) {
|
|
| 59 |
text.textContent = v.length ? labels[score] : '';
|
| 60 |
});
|
| 61 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
* Provides: makePasswordToggle(), passwordStrengthMeter()
|
| 4 |
*/
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
function makePasswordToggle(btnId, inputId, iconId) {
|
| 7 |
const btn = document.getElementById(btnId);
|
| 8 |
const input = document.getElementById(inputId);
|
|
|
|
| 13 |
const isHidden = input.type === 'password';
|
| 14 |
input.type = isHidden ? 'text' : 'password';
|
| 15 |
icon.innerHTML = isHidden
|
|
|
|
| 16 |
? '<path d="M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94"/>' +
|
| 17 |
'<path d="M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19"/>' +
|
| 18 |
'<line x1="1" y1="1" x2="23" y2="23"/>'
|
|
|
|
| 19 |
: '<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/>' +
|
| 20 |
'<circle cx="12" cy="12" r="3"/>';
|
| 21 |
});
|
| 22 |
}
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
function passwordStrengthMeter(inputId, barId, textId) {
|
| 25 |
const input = document.getElementById(inputId);
|
| 26 |
const bar = document.getElementById(barId);
|
|
|
|
| 45 |
text.textContent = v.length ? labels[score] : '';
|
| 46 |
});
|
| 47 |
}
|
| 48 |
+
|
| 49 |
+
// Check for cross-origin iframe context (Hugging Face Spaces)
|
| 50 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 51 |
+
let isFramed = false;
|
| 52 |
+
try {
|
| 53 |
+
isFramed = (window.self !== window.top);
|
| 54 |
+
} catch (e) {
|
| 55 |
+
isFramed = true;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
if (isFramed) {
|
| 59 |
+
const banner = document.createElement('div');
|
| 60 |
+
banner.style.cssText = `
|
| 61 |
+
position: fixed; top: 0; left: 0; right: 0;
|
| 62 |
+
background: #ef4444; color: white;
|
| 63 |
+
text-align: center; padding: 14px;
|
| 64 |
+
font-weight: 600; font-size: 15px;
|
| 65 |
+
z-index: 9999; box-shadow: 0 4px 12px rgba(0,0,0,0.5);
|
| 66 |
+
`;
|
| 67 |
+
banner.innerHTML = `
|
| 68 |
+
<div style="max-width: 800px; margin: 0 auto; display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 10px;">
|
| 69 |
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" style="flex-shrink: 0;"><path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>
|
| 70 |
+
<span>Browsers block login cookies inside iframes.</span>
|
| 71 |
+
<a href="${window.location.href}" target="_blank" style="background: white; color: #ef4444; padding: 4px 12px; border-radius: 4px; text-decoration: none; font-weight: bold; font-size: 13px; margin-left: 8px; white-space: nowrap;">
|
| 72 |
+
Open App in New Tab
|
| 73 |
+
</a>
|
| 74 |
+
</div>
|
| 75 |
+
`;
|
| 76 |
+
document.body.prepend(banner);
|
| 77 |
+
|
| 78 |
+
// Adjust layout to prevent overlap
|
| 79 |
+
const authPage = document.querySelector('.auth-page');
|
| 80 |
+
if (authPage) authPage.style.marginTop = '60px';
|
| 81 |
+
const mainHeader = document.querySelector('header');
|
| 82 |
+
if (mainHeader) mainHeader.style.marginTop = '50px';
|
| 83 |
+
}
|
| 84 |
+
});
|