Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Sync from GitHub via hub-sync
Browse files
src/app/api/auth/session/route.ts
CHANGED
|
@@ -21,11 +21,20 @@ export async function POST(req: NextRequest) {
|
|
| 21 |
return new NextResponse("Empty token", { status: 400 });
|
| 22 |
}
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
const res = new NextResponse(null, { status: 204 });
|
|
|
|
| 25 |
res.cookies.set(COOKIE_NAME, token, {
|
| 26 |
httpOnly: true,
|
| 27 |
-
secure:
|
| 28 |
-
sameSite: "lax",
|
|
|
|
| 29 |
path: "/",
|
| 30 |
maxAge: COOKIE_MAX_AGE_SECONDS,
|
| 31 |
});
|
|
@@ -33,7 +42,19 @@ export async function POST(req: NextRequest) {
|
|
| 33 |
}
|
| 34 |
|
| 35 |
export async function DELETE() {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
const res = new NextResponse(null, { status: 204 });
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
return res;
|
| 39 |
}
|
|
|
|
| 21 |
return new NextResponse("Empty token", { status: 400 });
|
| 22 |
}
|
| 23 |
|
| 24 |
+
// The Space is iframed inside huggingface.co/spaces/<owner>/<name>, so the
|
| 25 |
+
// top-level site differs from the cookie's site (*.hf.space). SameSite=Lax
|
| 26 |
+
// would block the cookie on subresource requests like <video> in that
|
| 27 |
+
// cross-site embedding context, which is exactly when we need it. Use
|
| 28 |
+
// SameSite=None + Secure + Partitioned (CHIPS) so the cookie rides along
|
| 29 |
+
// on subresource requests inside the iframe while remaining isolated to
|
| 30 |
+
// the (top-frame, this-domain) pair.
|
| 31 |
const res = new NextResponse(null, { status: 204 });
|
| 32 |
+
const isProd = process.env.NODE_ENV === "production";
|
| 33 |
res.cookies.set(COOKIE_NAME, token, {
|
| 34 |
httpOnly: true,
|
| 35 |
+
secure: isProd,
|
| 36 |
+
sameSite: isProd ? "none" : "lax",
|
| 37 |
+
partitioned: isProd,
|
| 38 |
path: "/",
|
| 39 |
maxAge: COOKIE_MAX_AGE_SECONDS,
|
| 40 |
});
|
|
|
|
| 42 |
}
|
| 43 |
|
| 44 |
export async function DELETE() {
|
| 45 |
+
// To clear a Partitioned cookie, the clearing Set-Cookie must include the
|
| 46 |
+
// Partitioned attribute too — otherwise it lands in a different cookie
|
| 47 |
+
// jar than the one we're trying to clear. Mirror the same attributes used
|
| 48 |
+
// when setting it, with maxAge=0 so it expires immediately.
|
| 49 |
const res = new NextResponse(null, { status: 204 });
|
| 50 |
+
const isProd = process.env.NODE_ENV === "production";
|
| 51 |
+
res.cookies.set(COOKIE_NAME, "", {
|
| 52 |
+
httpOnly: true,
|
| 53 |
+
secure: isProd,
|
| 54 |
+
sameSite: isProd ? "none" : "lax",
|
| 55 |
+
partitioned: isProd,
|
| 56 |
+
path: "/",
|
| 57 |
+
maxAge: 0,
|
| 58 |
+
});
|
| 59 |
return res;
|
| 60 |
}
|