fix(auth): avoid cookie domain on IP hosts
This commit is contained in:
parent
fc063df878
commit
565e29c74f
@ -1,10 +1,13 @@
|
|||||||
import type { NextAuthConfig } from "next-auth";
|
import type { NextAuthConfig } from "next-auth";
|
||||||
|
import { isIP } from "node:net";
|
||||||
|
|
||||||
export function buildAuthConfig(authUrl?: string | null): NextAuthConfig {
|
export function buildAuthConfig(authUrl?: string | null): NextAuthConfig {
|
||||||
const resolvedAuthUrl = authUrl || process.env.AUTH_URL || "";
|
const resolvedAuthUrl = authUrl || process.env.AUTH_URL || "";
|
||||||
const isSecure = resolvedAuthUrl.startsWith("https://");
|
const isSecure = resolvedAuthUrl.startsWith("https://");
|
||||||
const hostName = resolvedAuthUrl ? new URL(resolvedAuthUrl).hostname : undefined;
|
const hostName = resolvedAuthUrl ? new URL(resolvedAuthUrl).hostname : undefined;
|
||||||
const cookieDomain = hostName && hostName !== "localhost" ? hostName : undefined;
|
// Browsers may reject `Domain` cookies for IP hosts; keep them host-only in that case.
|
||||||
|
const cookieDomain =
|
||||||
|
hostName && hostName !== "localhost" && isIP(hostName) === 0 ? hostName : undefined;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
trustHost: true,
|
trustHost: true,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user