Skip to content

Conversation

@na-trium-144
Copy link
Contributor

@na-trium-144 na-trium-144 commented Oct 25, 2025

close #61

@na-trium-144 na-trium-144 marked this pull request as draft October 25, 2025 13:03
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Oct 25, 2025

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
my-code 02c903c Commit Preview URL

Branch Preview URL
Oct 25 2025, 06:36 PM

@na-trium-144 na-trium-144 marked this pull request as ready for review October 25, 2025 18:22
@na-trium-144 na-trium-144 requested a review from Copilot October 25, 2025 18:22
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a login functionality using better-auth with anonymous authentication and OAuth providers (GitHub/Google), replacing the previous localStorage-based chat history with a PostgreSQL database managed by Prisma.

Key changes:

  • Added Prisma schema with User, Session, Account, Chat, and Message models for database-backed authentication and chat storage
  • Integrated better-auth with anonymous login and OAuth providers
  • Migrated chat history from localStorage to database with automatic chat migration when anonymous users link accounts

Reviewed Changes

Copilot reviewed 18 out of 21 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
prisma/schema.prisma Defines database schema for authentication (User, Session, Account, Verification) and chat functionality (Chat, Message)
prisma.config.ts Configures Prisma with PostgreSQL datasource and migration settings
package.json Adds prisma, @prisma/client, better-auth, and dotenv dependencies; updates scripts to run prisma generate
app/sidebar.tsx Adds AccountMenu component to sidebar header
app/navbar.tsx Adds AccountMenu component to navbar
app/lib/prisma.ts Exports configured PrismaClient instance
app/lib/chatHistory.ts Implements server-side chat CRUD operations with authentication checks and user migration
app/lib/auth.ts Configures better-auth with Prisma adapter, anonymous plugin, and OAuth providers
app/lib/auth-client.ts Creates client-side auth instance with anonymous plugin
app/layout.tsx Adds AutoAnonymousLogin component for automatic anonymous authentication
app/api/auth/[...all]/route.ts Creates Next.js API route handler for better-auth endpoints
app/actions/chatActions.ts Updates askAI to save chats to database and return ChatWithMessages type
app/accountMenu.tsx Implements UI components for login/logout and account menu with OAuth integration
app/[docs_id]/pageContent.tsx Updates to use database-backed chat histories with new data structure
app/[docs_id]/page.tsx Fetches initial chat histories from database via getChat
app/[docs_id]/chatHistory.tsx Refactors chat history context to use database-backed ChatWithMessages type
app/[docs_id]/chatForm.tsx Updates to work with new chat data structure and server action response
README.md Documents setup instructions for Prisma development environment and production OAuth configuration

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

response: "",
error: "予期せぬエラーが発生しました。",
targetSectionId: sectionContent.find((s) => s.inView)?.sectionId || "",
error: String(error),
Copy link

Copilot AI Oct 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Converting the error to a string with String(error) may produce unhelpful messages like '[object Object]'. Extract the error message properly: error instanceof Error ? error.message : 'An unexpected error occurred'.

Suggested change
error: String(error),
error: error instanceof Error ? error.message : 'An unexpected error occurred',

Copilot uses AI. Check for mistakes.
const aiMessage: ChatMessage = { sender: "ai", text: result.response };
const chatId = addChat(result.targetSectionId, [userMessage, aiMessage]);
addChat(result.chat);
// TODO: chatIdが指す対象の回答にフォーカス
Copy link

Copilot AI Oct 25, 2025

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.

Suggested change
// TODO: chatIdが指す対象の回答にフォーカス
// TODO: result.chat.chatIdが指す対象の回答にフォーカス

Copilot uses AI. Check for mistakes.
@na-trium-144 na-trium-144 merged commit b74201a into main Oct 25, 2025
3 checks passed
@na-trium-144 na-trium-144 deleted the auth branch October 25, 2025 18:38
@na-trium-144
Copy link
Contributor Author

プレビューだとなんか動作しないが、ログも出なくて何が起きているかわからんので、一旦マージしちゃう

na-trium-144 added a commit that referenced this pull request Oct 25, 2025
This reverts commit b74201a, reversing
changes made to d8ce0f4.
na-trium-144 added a commit that referenced this pull request Oct 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

チャット履歴をlocalStorageではなくサーバー側に保存したい

2 participants