|
1 | 1 | import { betterAuth } from "better-auth"; |
2 | 2 | import { prismaAdapter } from "better-auth/adapters/prisma"; |
3 | | -import { PrismaClient } from "@/generated/prisma/client"; |
| 3 | +import { PrismaClient } from "../generated/prisma/client"; |
4 | 4 | import { getCloudflareContext } from "@opennextjs/cloudflare"; |
| 5 | +import { anonymous } from "better-auth/plugins"; |
5 | 6 |
|
6 | 7 | const prisma = new PrismaClient(); |
7 | 8 |
|
| 9 | +// eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 10 | +let cloudflareEnv: any; |
| 11 | +try { |
| 12 | + cloudflareEnv = getCloudflareContext().env; |
| 13 | +} catch { |
| 14 | + // @better-auth/cli generate を実行する際には initOpenNextCloudflareForDev がセットアップされていない環境になっている |
| 15 | + cloudflareEnv = {}; |
| 16 | +} |
8 | 17 | export const auth = betterAuth({ |
9 | 18 | database: prismaAdapter(prisma, { |
10 | 19 | provider: "postgresql", |
11 | 20 | }), |
| 21 | + plugins: [ |
| 22 | + anonymous({ |
| 23 | + onLinkAccount: async ({ anonymousUser, newUser }) => { |
| 24 | + // TODO |
| 25 | + }, |
| 26 | + }), |
| 27 | + ], |
12 | 28 | socialProviders: { |
13 | 29 | github: { |
14 | | - clientId: |
15 | | - process.env.GITHUB_CLIENT_ID ?? |
16 | | - // eslint-disable-next-line @typescript-eslint/no-explicit-any |
17 | | - (getCloudflareContext().env as any).GITHUB_CLIENT_ID, |
| 30 | + clientId: process.env.GITHUB_CLIENT_ID ?? cloudflareEnv.GITHUB_CLIENT_ID, |
18 | 31 | clientSecret: |
19 | | - process.env.GITHUB_CLIENT_SECRET ?? |
20 | | - // eslint-disable-next-line @typescript-eslint/no-explicit-any |
21 | | - (getCloudflareContext().env as any).GITHUB_CLIENT_SECRET, |
| 32 | + process.env.GITHUB_CLIENT_SECRET ?? cloudflareEnv.GITHUB_CLIENT_SECRET, |
22 | 33 | }, |
23 | 34 | google: { |
24 | | - clientId: |
25 | | - process.env.GOOGLE_CLIENT_ID ?? |
26 | | - // eslint-disable-next-line @typescript-eslint/no-explicit-any |
27 | | - (getCloudflareContext().env as any).GOOGLE_CLIENT_ID, |
| 35 | + clientId: process.env.GOOGLE_CLIENT_ID ?? cloudflareEnv.GOOGLE_CLIENT_ID, |
28 | 36 | clientSecret: |
29 | | - process.env.GOOGLE_CLIENT_SECRET ?? |
30 | | - // eslint-disable-next-line @typescript-eslint/no-explicit-any |
31 | | - (getCloudflareContext().env as any).GOOGLE_CLIENT_SECRET, |
| 37 | + process.env.GOOGLE_CLIENT_SECRET ?? cloudflareEnv.GOOGLE_CLIENT_SECRET, |
32 | 38 | }, |
33 | 39 | }, |
34 | 40 | }); |
0 commit comments