ai-chatbot/app/(auth)/auth.config.ts
Your Name 3f3523f1bb
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled
新版首页支持弹窗登录并接入Google后台配置
2026-02-14 00:39:46 +08:00

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://");
const hostName = resolvedAuthUrl ? new URL(resolvedAuthUrl).hostname : undefined;
const cookieDomain = hostName && hostName !== "localhost" ? hostName : 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: {},
};
}