mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-09 12:16:36 +00:00
add period to cookie
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import { cookies } from "next/headers";
|
import { cookies } from "next/headers";
|
||||||
import { ResponseT } from "@server/types/Response";
|
import { ResponseT } from "@server/types/Response";
|
||||||
|
import { pullEnv } from "@app/lib/pullEnv";
|
||||||
|
|
||||||
type CookieOptions = {
|
type CookieOptions = {
|
||||||
path?: string;
|
path?: string;
|
||||||
@@ -10,6 +11,7 @@ type CookieOptions = {
|
|||||||
sameSite?: "lax" | "strict" | "none";
|
sameSite?: "lax" | "strict" | "none";
|
||||||
expires?: Date;
|
expires?: Date;
|
||||||
maxAge?: number;
|
maxAge?: number;
|
||||||
|
domain?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
function parseSetCookieString(setCookie: string): {
|
function parseSetCookieString(setCookie: string): {
|
||||||
@@ -22,6 +24,8 @@ function parseSetCookieString(setCookie: string): {
|
|||||||
const [name, ...valParts] = nameValue.split("=");
|
const [name, ...valParts] = nameValue.split("=");
|
||||||
const value = valParts.join("="); // handles '=' inside JWT
|
const value = valParts.join("="); // handles '=' inside JWT
|
||||||
|
|
||||||
|
const env = pullEnv();
|
||||||
|
|
||||||
const options: CookieOptions = {};
|
const options: CookieOptions = {};
|
||||||
|
|
||||||
for (const attr of attrParts) {
|
for (const attr of attrParts) {
|
||||||
@@ -46,6 +50,18 @@ function parseSetCookieString(setCookie: string): {
|
|||||||
case "max-age":
|
case "max-age":
|
||||||
options.maxAge = parseInt(v, 10);
|
options.maxAge = parseInt(v, 10);
|
||||||
break;
|
break;
|
||||||
|
case "domain":
|
||||||
|
options.domain = v;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!options.domain) {
|
||||||
|
const d = env.app.dashboardUrl
|
||||||
|
? "." + new URL(env.app.dashboardUrl).hostname
|
||||||
|
: undefined;
|
||||||
|
if (d) {
|
||||||
|
options.domain = d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user