fix: use target=_blank for OAuth login (sandboxed iframe)
Browse filesHF Space iframe doesn't allow top-navigation. Use target="_blank"
to open OAuth flow in a new tab as recommended by HF docs.
After login, the callback redirects to /editor in that new tab.
Made-with: Cursor
- backend/src/server.ts +13 -4
backend/src/server.ts
CHANGED
|
@@ -292,7 +292,7 @@ function sendLoginPage(res: express.Response) {
|
|
| 292 |
<div class="card">
|
| 293 |
<h1>This article is not yet published</h1>
|
| 294 |
<p>Log in with your Hugging Face account to access the editor.</p>
|
| 295 |
-
<a class="btn" href="/oauth/authorize" target="
|
| 296 |
</div>
|
| 297 |
</body>
|
| 298 |
</html>`);
|
|
@@ -309,10 +309,19 @@ if (existsSync(staticDir)) {
|
|
| 309 |
const user = await resolveUser(token);
|
| 310 |
|
| 311 |
if (!user || !user.canEdit) {
|
| 312 |
-
// Not logged in or no write access →
|
|
|
|
| 313 |
res.status(200).send(`<!DOCTYPE html>
|
| 314 |
-
<html
|
| 315 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
return;
|
| 317 |
}
|
| 318 |
}
|
|
|
|
| 292 |
<div class="card">
|
| 293 |
<h1>This article is not yet published</h1>
|
| 294 |
<p>Log in with your Hugging Face account to access the editor.</p>
|
| 295 |
+
<a class="btn" href="/oauth/authorize" target="_blank">Sign in with Hugging Face</a>
|
| 296 |
</div>
|
| 297 |
</body>
|
| 298 |
</html>`);
|
|
|
|
| 309 |
const user = await resolveUser(token);
|
| 310 |
|
| 311 |
if (!user || !user.canEdit) {
|
| 312 |
+
// Not logged in or no write access → show login prompt
|
| 313 |
+
// Can't navigate top frame from sandboxed iframe, so show a button
|
| 314 |
res.status(200).send(`<!DOCTYPE html>
|
| 315 |
+
<html lang="en">
|
| 316 |
+
<head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/>
|
| 317 |
+
<title>Sign in required</title>
|
| 318 |
+
<style>*{margin:0;padding:0;box-sizing:border-box}body{display:flex;align-items:center;justify-content:center;height:100vh;font-family:system-ui,-apple-system,sans-serif;background:#0a0a0a;color:#aaa}.card{text-align:center;max-width:420px;padding:2rem}h1{color:#fff;font-size:1.5rem;margin-bottom:.5rem}p{margin-bottom:1.5rem;line-height:1.5}a.btn{display:inline-block;padding:.6rem 1.5rem;border-radius:8px;background:#958DF1;color:#fff;text-decoration:none;font-weight:500;transition:opacity .15s}a.btn:hover{opacity:.85}</style></head>
|
| 319 |
+
<body><div class="card">
|
| 320 |
+
<h1>Editor access</h1>
|
| 321 |
+
<p>Sign in with your Hugging Face account to start editing.</p>
|
| 322 |
+
<a class="btn" href="/oauth/authorize" target="_blank">Sign in with Hugging Face</a>
|
| 323 |
+
<p style="margin-top:1rem;font-size:.85rem;color:#666">After signing in, come back and <a href="/editor" style="color:#958DF1">refresh this page</a>.</p>
|
| 324 |
+
</div></body></html>`);
|
| 325 |
return;
|
| 326 |
}
|
| 327 |
}
|