2025-06-19 11:22:29 -04:00
|
|
|
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;
|
2024-11-23 23:31:22 -05:00
|
|
|
const sessionId = allCookies.get(cookieName)?.value ?? null;
|
2025-06-19 11:22:29 -04:00
|
|
|
|
|
|
|
// 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: {
|
2024-11-23 23:31:22 -05:00
|
|
|
Cookie: `${cookieName}=${sessionId}`,
|
2025-06-19 11:22:29 -04:00
|
|
|
...otherHeadersObject
|
2024-11-23 23:31:22 -05:00
|
|
|
},
|
|
|
|
};
|
2024-10-14 15:00:10 -04:00
|
|
|
}
|