Use this skill when creating or reviewing Next.js Route Handlers (app/api), adding rate limiting, input validation, or auth to API endpoints. Trigger words: API ルート, Route Handler, app/api, エンドポイント, レート制限, 入力検証, CORS, ヘッダー, 認証付き API, hardening.
server-only-secrets
Use this skill when handling secrets, API keys, environment variables, or ensuring server-only code never reaches the client bundle. Trigger words: シークレット, 秘密鍵, API キー, 環境変数, env, server-only, クライアント漏洩, NEXT_PUBLIC, バンドル.
含まれるファイル(1)
- SKILL.md2.1 KB
SKILL.md(原文)
インストールする前に、エージェントに与えられる指示の中身を確認できます。
Server-only Secrets
いつ使うか
- API キー・接続文字列・署名鍵など秘密情報を扱うとき。
- 「このモジュールは絶対クライアントに送りたくない」とき。
- env をクライアント/サーバーで切り分けるとき。
やること
- 秘密を含むモジュール先頭に
import 'server-only'を置く(誤って client に import されたらビルド失敗)。 - 公開してよい値だけ
NEXT_PUBLIC_接頭辞にする。それ以外は接頭辞を付けない。 - env は Zod で検証(
zod-validation参照)し、server 設定オブジェクトとして集約。 - 秘密は
.env.local(git 管理外)。.env.exampleにはプレースホルダのみ。
守るルール
- ✅ 秘密を扱うファイルに
import 'server-only'。 - ✅ クライアントに出してよい値だけ
NEXT_PUBLIC_。 - ✅ env は起動時に検証して型付きで公開。
- ❌ 秘密を
.env.example以外に書かない/コミットしない。 - ❌ 秘密を
console.logやレスポンスに含めない。
典型例(コード片)
// lib/server/payments.ts
import 'server-only'; // client から import されたらビルドで弾く
import { env } from '@/lib/env';
export function chargeClient() {
return new PaymentClient(env.PAYMENT_SECRET_KEY); // server 限定
}
# .env.example(プレースホルダのみ。実値は .env.local へ)
MONGODB_URI="mongodb+srv://USER:PASSWORD@CLUSTER/DB"
AUTH_SECRET="replace-with-32+chars-random"
アンチパターン
- 秘密キーを
NEXT_PUBLIC_にして全クライアントへ配布する。 server-onlyを付けず、共有ユーティリティ経由で client バンドルに混入。.env.localを誤ってコミット(.gitignoreを確認)。
レビュー
まだレビューはありません。使ってみた感想をお寄せください。
同じリポジトリのスキル
概要と使いどころ
Use this skill when implementing full-text search, autocomplete, or vector/semantic search and RAG with MongoDB Atlas. Trigger words: 全文検索, あいまい検索, オートコンプリート, ベクトル検索, セマンティック検索, 類似検索, Atlas Search, $search, $vectorSearch, RAG, embedding.
Use this skill when implementing sign-in, sessions, authorization checks, or protecting routes and Server Actions. Trigger words: 認証, ログイン, サインイン, セッション, 認可, 権限チェック, Better Auth, Auth.js, 保護, ミドルウェア, getSession.
Use this skill when starting a new session, opening this project for the first time, or when you need to recall the project's tech stack, hard rules, and which other skills exist. Trigger words: セッション開始, このプロジェクト, 全体像, どのスキル, 何から, getting started, overview.
Use this skill when setting up or modifying CI pipelines, GitHub Actions workflows, or automated checks (lint, typecheck, test, build) for this project. Trigger words: CI, GitHub Actions, ワークフロー, パイプライン, 自動テスト, lint チェック, typecheck, ビルド検証, .github/workflows.
Use this skill when writing end-to-end tests, browser automation, or verifying user flows in a real browser. Trigger words: E2E, Playwright, ブラウザテスト, ユーザーフロー, 結合テスト, シナリオテスト, ログインテスト, getByRole, expect.