ss
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user