Skip to content

Commit 717f065

Browse files
committed
better authをセットアップ
1 parent d8ce0f4 commit 717f065

File tree

10 files changed

+951
-11
lines changed

10 files changed

+951
-11
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,5 @@ yarn-error.log*
4242
# typescript
4343
*.tsbuildinfo
4444
next-env.d.ts
45+
46+
/app/generated/prisma

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,20 @@ https://my-code.utcode.net
77
npm ci
88
```
99

10-
ルートディレクトリに .env.local という名前のファイルを作成し、Gemini APIキーを設定してください
10+
ルートディレクトリに .env.local という名前のファイルを作成し、以下の内容を記述
1111
```dotenv
12-
API_KEY="XXXXXXXX"
12+
API_KEY=GeminiAPIキー
13+
BETTER_AUTH_URL=http://localhost:3000
1314
```
1415

16+
prismaの開発環境を起動
17+
(.env にDATABASE_URLが自動的に追加される)
18+
```bash
19+
npx prisma dev
20+
```
21+
22+
<!-- 本番環境では BETTER_AUTH_SECRET と DATABASE_URL の設定も必要です。 -->
23+
1524
## 開発環境
1625

1726
```bash

app/api/auth/[...all]/route.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { auth } from "@/lib/auth"; // path to your auth file
2+
import { toNextJsHandler } from "better-auth/next-js";
3+
4+
export const { POST, GET } = toNextJsHandler(auth);

app/lib/auth-client.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { createAuthClient } from "better-auth/react"
2+
export const authClient = createAuthClient({
3+
/** The base URL of the server (optional if you're using the same domain) */
4+
// baseURL: "http://localhost:3000"
5+
})

app/lib/auth.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { betterAuth } from "better-auth";
2+
import { prismaAdapter } from "better-auth/adapters/prisma";
3+
import { PrismaClient } from "@/generated/prisma/client";
4+
5+
const prisma = new PrismaClient();
6+
7+
export const auth = betterAuth({
8+
database: prismaAdapter(prisma, {
9+
provider: "postgresql",
10+
}),
11+
emailAndPassword: {
12+
enabled: true,
13+
},
14+
});

0 commit comments

Comments
 (0)