Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
26 changes: 9 additions & 17 deletions auth.config.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
import type { NextAuthConfig } from "next-auth";
import GitHub from "next-auth/providers/github";

Check warning on line 2 in auth.config.ts

View workflow job for this annotation

GitHub Actions / build

'GitHub' is defined but never used

Check warning on line 2 in auth.config.ts

View workflow job for this annotation

GitHub Actions / build

'GitHub' is defined but never used. Allowed unused vars must match /^_/u

// 在本地开发环境允许没有 .env 的协作者运行站点,因此先尝试读取两个常见的密钥变量,缺失时再使用内置的开发兜底值。
const envSecret = process.env.AUTH_SECRET ?? process.env.NEXTAUTH_SECRET;

// 开发环境允许兜底,生产环境必须显式配置
const secret =
envSecret ??
(process.env.NODE_ENV !== "production"
? "__involutionhell_dev_secret__"
: undefined);
(process.env.NODE_ENV === "production"
? undefined
: "__involutionhell_dev_secret__");

if (!envSecret && process.env.NODE_ENV !== "production") {
console.warn(
"[auth] AUTH_SECRET missing – using development fallback secret",
);
}

if (!secret) {
throw new Error("[auth] AUTH_SECRET is required in production environments");
if (process.env.NODE_ENV === "production" && !envSecret) {
throw new Error("[auth] AUTH_SECRET (or NEXTAUTH_SECRET) must be set in production");
}

export const authConfig = {
providers: [],
secret,
pages: {
signIn: "/login",
Expand Down Expand Up @@ -69,16 +72,5 @@
return extendedToken;
},
},
providers: [
GitHub({
profile(profile) {
return {
id: profile.id.toString(),
name: profile.name ?? profile.login,
email: profile.email,
image: profile.avatar_url,
};
},
}),
],

} satisfies NextAuthConfig;
Loading