fosrl.pangolin/src/lib/api/cookies.ts

23 lines
676 B
TypeScript
Raw Normal View History

import { cookies, headers } from "next/headers";
2025-01-04 20:22:01 -05:00
import { pullEnv } from "../pullEnv";
2024-10-14 15:00:10 -04:00
2024-10-23 13:30:23 -04:00
export async function authCookieHeader() {
2025-01-04 20:22:01 -05:00
const env = pullEnv();
2024-10-23 13:30:23 -04:00
const allCookies = await cookies();
2025-01-04 20:22:01 -05:00
const cookieName = env.server.sessionCookieName;
const sessionId = allCookies.get(cookieName)?.value ?? null;
// all other headers
// this is needed to pass through x-forwarded-for, x-forwarded-proto, etc.
const otherHeaders = await headers();
const otherHeadersObject = Object.fromEntries(otherHeaders.entries());
2024-10-14 15:00:10 -04:00
return {
headers: {
Cookie: `${cookieName}=${sessionId}`,
...otherHeadersObject
},
};
2024-10-14 15:00:10 -04:00
}