-
Notifications
You must be signed in to change notification settings - Fork 1
ログイン機能 #71
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
Merged
Merged
ログイン機能 #71
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
717f065
better authをセットアップ
na-trium-144 2767a2f
ログインボタンを追加
na-trium-144 f8fbe5f
anonymousプラグインを追加
na-trium-144 44aca80
チャットがサーバーに保存されるようになった
na-trium-144 62960eb
idはincrementでないほうがよい説 (しらんけど)
na-trium-144 3f3cb6f
ソーシャルログインとログアウトの挙動を実装
na-trium-144 d12217b
build前にprisma generate
na-trium-144 02c903c
DATABASE_URL環境変数がなくても動くよう修正
na-trium-144 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 |
|---|---|---|
|
|
@@ -42,3 +42,5 @@ yarn-error.log* | |
| # typescript | ||
| *.tsbuildinfo | ||
| next-env.d.ts | ||
|
|
||
| /app/generated/prisma | ||
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,136 @@ | ||
| "use client"; | ||
|
|
||
| import { authClient } from "@/lib/auth-client"; | ||
| import { usePathname } from "next/navigation"; | ||
| import { useEffect } from "react"; | ||
|
|
||
| export function AutoAnonymousLogin() { | ||
| const { data: session, isPending } = authClient.useSession(); | ||
| useEffect(() => { | ||
| if (!isPending && !session) { | ||
| authClient.signIn.anonymous(); | ||
| } | ||
| }, [isPending, session]); | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| export function AccountMenu() { | ||
| const { data: session, isPending } = authClient.useSession(); | ||
| const pathname = usePathname(); | ||
|
|
||
| const signout = () => { | ||
| if ( | ||
| window.confirm( | ||
| "ログアウトしますか?\nチャット履歴はこの端末上で見られなくなりますが、再度ログインすることでアクセスできます。" | ||
| ) | ||
| ) { | ||
| authClient.signOut({ | ||
| fetchOptions: { | ||
| onSuccess: () => window.location.reload(), | ||
| }, | ||
| }); | ||
| } | ||
| }; | ||
| const signoutFromAnonymous = () => { | ||
| if (window.confirm("チャット履歴は削除され、アクセスできなくなります。")) { | ||
| authClient.signOut({ | ||
| fetchOptions: { | ||
| onSuccess: () => window.location.reload(), | ||
| }, | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| if (isPending) { | ||
| return <div className="w-10 h-10 skeleton rounded-full"></div>; | ||
| } | ||
|
|
||
| if (session && !session.user.isAnonymous) { | ||
| return ( | ||
| <div className="dropdown dropdown-end"> | ||
| <label tabIndex={0} className="btn btn-ghost btn-circle avatar"> | ||
| <div className="w-8 h-8 rounded-full"> | ||
| <img | ||
| src={ | ||
| session.user?.image ?? | ||
| `https://avatar.vercel.sh/${session.user?.name}` | ||
| } | ||
| alt="user avatar" | ||
| /> | ||
| </div> | ||
| </label> | ||
| <ul | ||
| tabIndex={0} | ||
| className="mt-3 z-[1] p-2 shadow menu menu-sm dropdown-content bg-base-100 rounded-box w-52" | ||
| > | ||
| <li> | ||
| <a onClick={signout}>ログアウト</a> | ||
| </li> | ||
| </ul> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <div className="dropdown dropdown-end"> | ||
| <label tabIndex={0} className="btn btn-ghost btn-circle avatar"> | ||
| <div className="w-8 h-8 rounded-full"> | ||
| <svg | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| fill="none" | ||
| viewBox="0 0 24 24" | ||
| strokeWidth={1.5} | ||
| stroke="currentColor" | ||
| className="w-full h-full" | ||
| > | ||
| <path | ||
| strokeLinecap="round" | ||
| strokeLinejoin="round" | ||
| d="M17.982 18.725A7.488 7.488 0 0 0 12 15.75a7.488 7.488 0 0 0-5.982 2.975m11.963 0a9 9 0 1 0-11.963 0m11.963 0A8.966 8.966 0 0 1 12 21a8.966 8.966 0 0 1-5.982-2.275M15 9.75a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z" | ||
| /> | ||
| </svg> | ||
| </div> | ||
| </label> | ||
| <ul className="z-1 shadow-md dropdown-content bg-base-100 rounded-box menu w-64"> | ||
na-trium-144 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <li className="menu-title"> | ||
| ログインすると、チャット履歴を保存し別のデバイスからもアクセスできるようになります。 | ||
| </li> | ||
| <li> | ||
| <button | ||
| onClick={() => | ||
| authClient.signIn.social({ | ||
| provider: "github", | ||
| callbackURL: pathname, | ||
| }) | ||
| } | ||
| > | ||
| GitHub でログイン | ||
| </button> | ||
| </li> | ||
| <li> | ||
| <button | ||
| onClick={() => | ||
| authClient.signIn.social({ | ||
| provider: "google", | ||
| callbackURL: pathname, | ||
| }) | ||
| } | ||
| > | ||
| Google でログイン | ||
| </button> | ||
| </li> | ||
| {session?.user && ( | ||
| <> | ||
| <div className="divider my-0" /> | ||
| <li> | ||
| <button onClick={signoutFromAnonymous}> | ||
| この端末上のデータを削除 | ||
| </button> | ||
| </li> | ||
| </> | ||
| )} | ||
| </ul> | ||
| </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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The chatId variable is no longer defined after removing the assignment. If the TODO is still relevant, it should reference result.chat.chatId instead.