This commit is contained in:
root
2026-06-07 19:18:24 +08:00
parent a1daa040ef
commit 32b900547a
16 changed files with 127 additions and 427 deletions

View File

@@ -4,6 +4,8 @@
* 本地开发不设置 domain,避免 IP 访问时 cookie 失效
*/
import { IS_DEVELOPMENT, IS_PRODUCTION } from "@/config/runtime-env";
const COOKIE_NAME = "pb_session";
const COOKIE_MAX_AGE = 60 * 60 * 24 * 365;
@@ -16,18 +18,17 @@ export function getHostFromRequest(request: { headers: { get: (k: string) => str
}
export function getCookieOptions(clear = false, requestHost?: string) {
const isProd = process.env.NODE_ENV === "production";
const domain = process.env.AUTH_COOKIE_DOMAIN?.trim();
const opts: Record<string, unknown> = {
path: "/",
maxAge: clear ? 0 : COOKIE_MAX_AGE,
secure: isProd,
secure: IS_PRODUCTION,
sameSite: "lax" as const,
httpOnly: true,
};
if (domain && isProd) {
if (domain && IS_PRODUCTION) {
opts.domain = domain;
} else if (!isProd && requestHost && /^(\d{1,3}\.){3}\d{1,3}$/.test(requestHost)) {
} else if (IS_DEVELOPMENT && requestHost && /^(\d{1,3}\.){3}\d{1,3}$/.test(requestHost)) {
opts.domain = requestHost;
}
return opts;

View File

@@ -4,6 +4,7 @@
*/
import { DEFAULT_PAYMENT_API_URL, DEFAULT_SITE_URL } from "@/config/digital/domain.config";
import { IS_DEVELOPMENT } from "@/config/runtime-env";
/** 支付 API 地址(payjsapi) */
export const PAYMENT_API_URL =
@@ -14,4 +15,4 @@ export const SITE_URL =
process.env.NEXT_PUBLIC_SITE_URL || DEFAULT_SITE_URL;
/** 是否为本地开发 */
export const IS_DEV = process.env.NODE_ENV === "development";
export const IS_DEV = IS_DEVELOPMENT;