-
Notifications
You must be signed in to change notification settings - Fork 0
/
route.ts
28 lines (22 loc) · 821 Bytes
/
route.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { NextRequest, NextResponse } from "next/server";
import { splitCookiesString, parseSetCookie } from "@edge-runtime/cookies";
export const runtime = "edge";
export const GET = async (req: NextRequest) => {
const url = `${req.nextUrl.origin}/api/cookie`;
const sessionResponse = await fetch(url, {
credentials: "include",
});
const setCookieHeader = sessionResponse.headers.get("set-cookie");
const response = NextResponse.json({
route: "success. Returns multiple Set-Cookie headers",
});
if (setCookieHeader) {
const splitCookie = splitCookiesString(setCookieHeader);
const parsedCookie = splitCookie.map((cookie) => parseSetCookie(cookie));
parsedCookie.forEach((cookie) => {
if (!cookie) return;
response.cookies.set(cookie);
});
}
return response;
};