fix: OAuth login works inside HF Space iframe
Browse files- Login link uses target="_top" to break out of iframe
- /editor redirect uses window.top.location instead of server redirect
Made-with: Cursor
- backend/src/server.ts +5 -3
backend/src/server.ts
CHANGED
|
@@ -285,7 +285,7 @@ function sendLoginPage(res: express.Response) {
|
|
| 285 |
<div class="card">
|
| 286 |
<h1>This article is not yet published</h1>
|
| 287 |
<p>Log in with your Hugging Face account to access the editor.</p>
|
| 288 |
-
<a class="btn" href="/oauth/authorize">Sign in with Hugging Face</a>
|
| 289 |
</div>
|
| 290 |
</body>
|
| 291 |
</html>`);
|
|
@@ -302,8 +302,10 @@ if (existsSync(staticDir)) {
|
|
| 302 |
const user = await resolveUser(token);
|
| 303 |
|
| 304 |
if (!user || !user.canEdit) {
|
| 305 |
-
// Not logged in or no write access →
|
| 306 |
-
res.
|
|
|
|
|
|
|
| 307 |
return;
|
| 308 |
}
|
| 309 |
}
|
|
|
|
| 285 |
<div class="card">
|
| 286 |
<h1>This article is not yet published</h1>
|
| 287 |
<p>Log in with your Hugging Face account to access the editor.</p>
|
| 288 |
+
<a class="btn" href="/oauth/authorize" target="_top">Sign in with Hugging Face</a>
|
| 289 |
</div>
|
| 290 |
</body>
|
| 291 |
</html>`);
|
|
|
|
| 302 |
const user = await resolveUser(token);
|
| 303 |
|
| 304 |
if (!user || !user.canEdit) {
|
| 305 |
+
// Not logged in or no write access → break out of iframe to OAuth
|
| 306 |
+
res.status(200).send(`<!DOCTYPE html>
|
| 307 |
+
<html><head><script>window.top.location.href="/oauth/authorize";</script></head>
|
| 308 |
+
<body>Redirecting to login...</body></html>`);
|
| 309 |
return;
|
| 310 |
}
|
| 311 |
}
|