a tool for shared writing and social publishing
1import { cookies, headers } from "next/headers";
2import { isProductionDomain } from "./utils/isProductionDeployment";
3
4export async function setAuthToken(tokenID: string) {
5 let c = await cookies();
6 let host = (await headers()).get("host");
7 c.set("auth_token", tokenID, {
8 maxAge: 60 * 60 * 24 * 365,
9 secure: process.env.NODE_ENV === "production",
10 domain: isProductionDomain() ? host! : undefined,
11 httpOnly: true,
12 sameSite: "lax",
13 });
14}
15
16export async function removeAuthToken() {
17 let c = await cookies();
18 c.delete({
19 name: "auth_token",
20 domain: isProductionDomain() ? ".leaflet.pub" : undefined,
21 });
22}