50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import type { NextAuthConfig } from "next-auth";
|
|
|
|
// 检测是否为 HTTPS 环境
|
|
const isSecure = process.env.AUTH_URL?.startsWith("https://") ?? false;
|
|
const hostName = process.env.AUTH_URL ? new URL(process.env.AUTH_URL).hostname : undefined;
|
|
const cookieDomain = hostName && hostName !== "localhost" ? hostName : undefined;
|
|
|
|
export const authConfig = {
|
|
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: [
|
|
// added later in auth.ts since it requires bcrypt which is only compatible with Node.js
|
|
// while this file is also used in non-Node.js environments
|
|
],
|
|
callbacks: {},
|
|
} satisfies NextAuthConfig;
|