49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import type { NextAuthConfig } from "next-auth";
|
|
|
|
export function buildAuthConfig(authUrl?: string | null): NextAuthConfig {
|
|
const resolvedAuthUrl = authUrl || process.env.AUTH_URL || "";
|
|
const isSecure = resolvedAuthUrl.startsWith("https://");
|
|
// Use host-only cookies to avoid cross-domain login issues in multi-domain deployments.
|
|
const cookieDomain = undefined;
|
|
|
|
return {
|
|
trustHost: true,
|
|
pages: {
|
|
signIn: "/login",
|
|
newUser: "/",
|
|
},
|
|
cookies: {
|
|
sessionToken: {
|
|
name: isSecure ? "__Secure-authjs.session-token" : "authjs.session-token",
|
|
options: {
|
|
httpOnly: true,
|
|
sameSite: "lax",
|
|
path: "/",
|
|
secure: isSecure,
|
|
domain: cookieDomain,
|
|
},
|
|
},
|
|
callbackUrl: {
|
|
name: isSecure ? "__Secure-authjs.callback-url" : "authjs.callback-url",
|
|
options: {
|
|
sameSite: "lax",
|
|
path: "/",
|
|
secure: isSecure,
|
|
domain: cookieDomain,
|
|
},
|
|
},
|
|
csrfToken: {
|
|
name: isSecure ? "__Host-authjs.csrf-token" : "authjs.csrf-token",
|
|
options: {
|
|
httpOnly: true,
|
|
sameSite: "lax",
|
|
path: "/",
|
|
secure: isSecure,
|
|
},
|
|
},
|
|
},
|
|
providers: [],
|
|
callbacks: {},
|
|
};
|
|
}
|