Skip to content

ユーザー作成(管理者向け)

現時点では管理画面からのユーザー登録機能は未実装です。システム管理者は以下の方法でユーザーを作成できます。

方法 1: psql で直接作成

1. パスワードハッシュの生成

bcrypt でパスワードをハッシュ化する必要があります。

bash
# Node.js を使用
node -e "const bcrypt = require('bcryptjs'); console.log(bcrypt.hashSync('your_password', 10))"

# または htpasswd を使用
htpasswd -bnBC 10 "" your_password | tr -d ':\n'

2. ユーザーの挿入

sql
-- Docker環境の場合
docker exec -it iwa-cms-postgres-1 psql -U postgres -d iwa_cms

-- ユーザー作成
INSERT INTO users (name, email, password)
VALUES (
  'ユーザー名',
  'user@example.com',
  '$2a$10$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'  -- bcryptハッシュ
);

確認用クエリ

sql
-- ユーザー一覧
SELECT id, name, email, created_at FROM users;

方法 2: gRPC で作成

Postman での手順

  1. gRPC リクエストの作成

    • Postman で「New」→「gRPC」を選択
    • URL: localhost:8080(cms-service)
  2. proto ファイルのインポート

    • 「Service definition」タブで「Import .proto file」
    • pkg/proto/cms/v1/user.proto をインポート
    • 依存ファイルも必要に応じてインポート
  3. メソッドの選択

    • cms.v1.UserService/CreateUser を選択
  4. リクエストボディ

    json
    {
      "name": "ユーザー名",
      "email": "user@example.com",
      "password": "your_password"
    }
  5. 送信

    • 「Invoke」ボタンをクリック

grpcurl での手順

bash
# grpcurl のインストール(macOS)
brew install grpcurl

# ユーザー作成
grpcurl -plaintext \
  -d '{
    "name": "ユーザー名",
    "email": "user@example.com",
    "password": "your_password"
  }' \
  localhost:8080 \
  cms.v1.UserService/CreateUser

注意

gRPC エンドポイントは現在認証なしでアクセス可能です。

テーブル構造

users テーブル

カラム説明
idUUID自動生成
nameTEXTユーザー名
emailCITEXTメールアドレス(大文字小文字区別なし、ユニーク)
passwordTEXTbcrypt ハッシュ
created_atTIMESTAMPTZ作成日時
updated_atTIMESTAMPTZ更新日時

関連ページ

©2025 Hayato Iwasaki