-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Better Authでメール/パスワード認証を追加 #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
tknkaa
wants to merge
3
commits into
main
Choose a base branch
from
feature/better-auth
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,8 @@ | ||
| DATABASE_URL="file:./prisma/dev.db" | ||
| # 本番(Turso)では DATABASE_URL を下記のような形式にする: | ||
| # DATABASE_URL="libsql://<db-name>-<org>.turso.io?authToken=<token>" | ||
|
|
||
| # Better Authがセッション/Cookieの署名に使う秘密鍵。`openssl rand -base64 32` などで生成する | ||
| BETTER_AUTH_SECRET="" | ||
| # アプリのオリジン。本番ではデプロイ先のURLに変更する | ||
| BETTER_AUTH_URL="http://localhost:3000" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { toNextJsHandler } from "better-auth/next-js"; | ||
|
|
||
| import { auth } from "@/lib/auth"; | ||
|
|
||
| export const { GET, POST } = toNextJsHandler(auth); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import type { Metadata } from "next"; | ||
| import { Suspense } from "react"; | ||
|
|
||
| import LoginForm from "@/components/auth/LoginForm"; | ||
|
|
||
| export const metadata: Metadata = { | ||
| title: "ログイン | Vocabook", | ||
| }; | ||
|
|
||
| export default function LoginPage() { | ||
| return ( | ||
| <main className="flex flex-1 flex-col items-center px-6 py-24"> | ||
| <div className="w-full max-w-sm"> | ||
| <h1 className="mb-8 text-center text-3xl font-semibold tracking-tight text-black dark:text-zinc-50"> | ||
| ログイン | ||
| </h1> | ||
| {/* LoginForm内のuseSearchParams()が静的プリレンダリングをブロックしないようSuspenseで囲む */} | ||
| <Suspense> | ||
| <LoginForm /> | ||
| </Suspense> | ||
| </div> | ||
| </main> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import type { Metadata } from "next"; | ||
|
|
||
| import SignupForm from "@/components/auth/SignupForm"; | ||
|
|
||
| export const metadata: Metadata = { | ||
| title: "新規登録 | Vocabook", | ||
| }; | ||
|
|
||
| export default function SignupPage() { | ||
| return ( | ||
| <main className="flex flex-1 flex-col items-center px-6 py-24"> | ||
| <div className="w-full max-w-sm"> | ||
| <h1 className="mb-8 text-center text-3xl font-semibold tracking-tight text-black dark:text-zinc-50"> | ||
| 新規登録 | ||
| </h1> | ||
| <SignupForm /> | ||
| </div> | ||
| </main> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import Link from "next/link"; | ||
|
|
||
| import { getCurrentUser } from "@/lib/session"; | ||
| import LogoutButton from "@/components/auth/LogoutButton"; | ||
|
|
||
| // ヘッダーの中で唯一セッションを参照する部分。ここをSuspenseで囲むことで、 | ||
| // 他の静的な部分(ナビゲーションなど)まで動的レンダリングに巻き込まれるのを防ぐ | ||
| export default async function HeaderAuthStatus() { | ||
| const user = await getCurrentUser(); | ||
|
|
||
| if (user) { | ||
| return ( | ||
| <div className="flex items-center gap-3"> | ||
| <span className="hidden text-sm text-zinc-500 dark:text-zinc-400 sm:inline"> | ||
| {user.name} | ||
| </span> | ||
| <LogoutButton /> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <div className="flex items-center gap-3"> | ||
| <Link | ||
| href="/login" | ||
| className="text-sm font-medium text-zinc-600 transition-colors hover:text-emerald-500 dark:text-zinc-200 dark:hover:text-emerald-500" | ||
| > | ||
| ログイン | ||
| </Link> | ||
| <Link | ||
| href="/signup" | ||
| className="rounded-full bg-black px-4 py-1.5 text-sm font-medium text-white transition-colors hover:bg-zinc-800 dark:bg-zinc-50 dark:text-black dark:hover:bg-zinc-200" | ||
| > | ||
| 新規登録 | ||
| </Link> | ||
| </div> | ||
| ); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.