-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathauth.ts
More file actions
41 lines (39 loc) · 1.1 KB
/
auth.ts
File metadata and controls
41 lines (39 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import NextAuth from "next-auth";
import { authConfig } from "./auth.config";
import GitHub from "next-auth/providers/github";
import { PrismaAdapter } from "@auth/prisma-adapter";
import { prisma } from "@/lib/db";
export const { handlers, auth, signIn, signOut } = NextAuth(() => {
// 数据库适配器:仅在有 DATABASE_URL 时启用
const adapter = process.env.DATABASE_URL ? PrismaAdapter(prisma) : undefined;
if (!process.env.DATABASE_URL) {
console.warn("[auth] DATABASE_URL missing – running without Neon adapter");
}
return {
...authConfig,
providers: [
GitHub({
profile(profile) {
return {
id: profile.id.toString(), // 与数据库的整数主键兼容
name: profile.name ?? profile.login,
email: profile.email,
image: profile.avatar_url,
};
},
}),
],
...(adapter
? {
adapter,
session: {
strategy: "database" as const,
},
}
: {
session: {
strategy: "jwt" as const,
},
}),
};
});