Skip to content
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

passwordログイン #61

Merged
merged 1 commit into from
Jul 21, 2024
Merged

passwordログイン #61

merged 1 commit into from
Jul 21, 2024

Conversation

ttizze
Copy link
Owner

@ttizze ttizze commented Jul 21, 2024

Summary by CodeRabbit

## リリースノート

### New Feature
- ログイン機能を追加しました。Google認証とユーザー名・パスワードによる認証が可能です。
- 開発環境用のデータベースシードスクリプトを追加しました。

### Documentation
- README.mdを更新し、Googleログインの設定手順を削除し、簡易認証方法とseedコマンドの実行手順を追加しました。

### Chore
- `package.json`に新しいスクリプトを追加し、開発環境でのデータベースシードを実行する設定を含めました。

@ttizze ttizze merged commit 30d5db7 into main Jul 21, 2024
2 checks passed
@ttizze ttizze deleted the feature/password-login branch July 21, 2024 14:52
Copy link

github-actions bot commented Jul 21, 2024

Image description CodeRabbit

### ウォークスルー
この変更セットは、Googleログインの設定手順を削除し、開発環境用の簡易認証方法を追加しています。また、フォームベースの認証機能が実装され、データベースシードスクリプトが追加されています。

### 変更点
| ファイル | 要約 |
| --- | --- |
| README.md | Googleログインの設定手順を削除し、開発環境用の簡易認証方法と`SESSION_SECRET`の生成方法を追加。seedコマンドの実行手順も更新。 |
| web/package.json | `seed`スクリプトを追加し、開発環境でのデータベースシードを実行する設定を含む。 |
| web/prisma/seed.ts | 開発環境でのみ実行されるユーザーシーディングスクリプトを追加。bcryptを使用してパスワードをハッシュ化し、Prismaを用いてデータベースに保存。 |
| web/app/routes/auth.login.tsx | ログイン機能を追加。zodを使用したバリデーションスキーマ、フォーム作成、エラーメッセージ表示、Google認証とユーザー名・パスワードによる認証処理を含む。 |
| web/app/types.ts | `SafeUser`型から`openAIApiKey``claudeApiKey`を除外。 |
| web/app/utils/auth.server.ts | bcryptjsとremix-auth-formのインポートを追加し、フォームベースの認証戦略を実装。不要なAPIキーを除外。 |
| web/prisma/migrations/20240721105034_/migration.sql, web/prisma/migrations/20240721115647_/migration.sql, web/prisma/migrations/20240721123812_/migration.sql | `users`テーブルに`password`列を追加・削除するためのSQL文を含む。 |
| web/prisma/schema.prisma | `User`モデルにオプショナルな`password`フィールドを追加。 |

Uplevel your code reviews with CodeRabbit Pro

CodeRabbit Pro

If you like this project, please support us by purchasing the Pro version. The Pro version has advanced context, superior noise reduction and several proprietary improvements compared to the open source version. Moreover, CodeRabbit Pro is free for open source projects.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Image description CodeRabbit

Commits Files that changed from the base of the PR and between c6c9c17 and 06d0cbb commits.
Files selected (10)
  • README.md (2)
  • web/app/routes/auth.login.tsx (2)
  • web/app/types.ts (1)
  • web/app/utils/auth.server.ts (3)
  • web/package.json (1)
  • web/prisma/migrations/20240721105034_/migration.sql (1)
  • web/prisma/migrations/20240721115647_/migration.sql (1)
  • web/prisma/migrations/20240721123812_/migration.sql (1)
  • web/prisma/schema.prisma (1)
  • web/prisma/seed.ts (1)
Review comments generated (15)
  • Review: 6
  • LGTM: 9

Tips

Chat with Image description CodeRabbit Bot (@coderabbitai)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @coderabbitai in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @coderabbitai: ignore anywhere in the PR description to pause further reviews from the bot.

@@ -9,7 +9,11 @@
"dev": "remix vite:dev",
"start": "remix-serve ./build/server/index.js",
"typecheck": "tsc",
"check": "bunx @biomejs/biome check --write ."
"check": "bunx @biomejs/biome check --write .",
"seed": "NODE_ENV=development prisma db seed"

Choose a reason for hiding this comment

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

Image description CodeRabbit

NODE_ENV=developmentの前後にスペースが含まれているため、意図しない動作を引き起こす可能性があります。スペースを削除してください。

-		"seed": "NODE_ENV=development  prisma db seed"
+		"seed": "NODE_ENV=development prisma db seed"

@@ -23,7 +56,7 @@ const googleStrategy = new GoogleStrategy<SafeUser>(
where: { email: profile.emails[0].value },
});
if (user) {
const { geminiApiKey, ...safeUser } = user;
const { password, geminiApiKey, openAIApiKey, claudeApiKey, ...safeUser } = user;

Choose a reason for hiding this comment

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

Image description CodeRabbit

passwordフィールドを削除する際に、他のAPIキーと同様にアンダースコアでプレフィックスを付けることで一貫性を保つべきです。

- 			const { password, geminiApiKey, openAIApiKey, claudeApiKey, ...safeUser } = user;
+ 			const { password: _, geminiApiKey, openAIApiKey, claudeApiKey, ...safeUser } = user;

@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "users" ADD COLUMN "password" TEXT;

Choose a reason for hiding this comment

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

Image description CodeRabbit

passwordカラムはユーザーのパスワードを保存するために使用されるため、セキュリティ上の理由から暗号化された形式で保存する必要があります。Prismaのマイグレーションファイルではなく、アプリケーションコード内でbcryptなどを使用してハッシュ化することが推奨されますが、ここではデータ型をTEXTからVARCHAR(255)に変更することを検討してください。

- ALTER TABLE "users" ADD COLUMN     "password" TEXT;
+ ALTER TABLE "users" ADD COLUMN     "password" VARCHAR(255);

@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "users" ADD COLUMN "password" TEXT;

Choose a reason for hiding this comment

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

Image description CodeRabbit

passwordカラムのデータ型をTEXTにするのは適切ではありません。パスワードはハッシュ化されて保存されるため、固定長の文字列として扱う方が良いです。例えば、VARCHAR(60)などを使用すると良いでしょう。

-ALTER TABLE "users" ADD COLUMN     "password" TEXT;
+ALTER TABLE "users" ADD COLUMN     "password" VARCHAR(60);

Comment on lines +7 to +9
if (process.env.NODE_ENV !== 'development' && !process.env.ALLOW_SEEDING) {
console.log('Seeding is only allowed in development environment')
return

Choose a reason for hiding this comment

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

Image description CodeRabbit

環境変数のチェックにおいて、ALLOW_SEEDINGが設定されていない場合にシードを実行しないようにするための条件が適切です。しかし、エラーメッセージをより具体的にして、なぜシードが許可されていないのかを明示することをお勧めします。

-    console.log('Seeding is only allowed in development environment')
+    console.log('Seeding is only allowed in development environment or when ALLOW_SEEDING is set')

return
}

const hashedPassword = await bcrypt.hash('devpassword', 10)

Choose a reason for hiding this comment

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

Image description CodeRabbit

パスワードのハッシュ化にはbcryptを使用していますが、ソルトラウンドの値を環境変数から取得することで、セキュリティと柔軟性を向上させることができます。

-   const hashedPassword = await bcrypt.hash('devpassword', 10)
+   const saltRounds = parseInt(process.env.SALT_ROUNDS) || 10
+   const hashedPassword = await bcrypt.hash('devpassword', saltRounds)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant