rafmacalaba commited on
Commit
559363f
Β·
1 Parent(s): c796a00

fix: open OAuth login in new tab to bypass iframe restrictions, auto-poll for cookie

Browse files
Files changed (2) hide show
  1. app/globals.css +2 -0
  2. app/page.js +22 -2
app/globals.css CHANGED
@@ -134,6 +134,8 @@ h4 {
134
  background: var(--accent);
135
  padding: 12px 28px;
136
  border-radius: 8px;
 
 
137
  text-decoration: none;
138
  transition: background 0.2s;
139
  }
 
134
  background: var(--accent);
135
  padding: 12px 28px;
136
  border-radius: 8px;
137
+ border: none;
138
+ cursor: pointer;
139
  text-decoration: none;
140
  transition: background 0.2s;
141
  }
app/page.js CHANGED
@@ -349,14 +349,34 @@ export default function Home() {
349
 
350
  // Gate: require HF OAuth login
351
  if (!annotatorName) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
352
  return (
353
  <div className="login-gate">
354
  <div className="login-card">
355
  <h1>πŸ”’ Annotation Tool</h1>
356
  <p>Sign in with your HuggingFace account to access the annotation tool.</p>
357
- <a href="/api/auth/login" className="btn btn-login-large">
358
  πŸ€— Sign in with HuggingFace
359
- </a>
360
  <p className="login-note">Only authorized annotators can access this tool.</p>
361
  </div>
362
  </div>
 
349
 
350
  // Gate: require HF OAuth login
351
  if (!annotatorName) {
352
+ const handleLogin = () => {
353
+ // Open login in a new tab to bypass iframe restrictions
354
+ window.open('/api/auth/login', '_blank');
355
+ // Poll for the cookie to appear (set by callback)
356
+ const poll = setInterval(() => {
357
+ try {
358
+ const cookie = document.cookie
359
+ .split('; ')
360
+ .find(c => c.startsWith('hf_user='));
361
+ if (cookie) {
362
+ clearInterval(poll);
363
+ const user = JSON.parse(decodeURIComponent(cookie.split('=').slice(1).join('=')));
364
+ if (user.username) {
365
+ setAnnotatorName(user.username);
366
+ }
367
+ }
368
+ } catch (e) { /* ignore */ }
369
+ }, 2000);
370
+ };
371
+
372
  return (
373
  <div className="login-gate">
374
  <div className="login-card">
375
  <h1>πŸ”’ Annotation Tool</h1>
376
  <p>Sign in with your HuggingFace account to access the annotation tool.</p>
377
+ <button onClick={handleLogin} className="btn btn-login-large">
378
  πŸ€— Sign in with HuggingFace
379
+ </button>
380
  <p className="login-note">Only authorized annotators can access this tool.</p>
381
  </div>
382
  </div>