Skip to content
cccskills
FreePublished on GitHub

zod-validation

Use this skill when validating API input, environment variables, form data, or DB responses at runtime boundaries. Trigger words: バリデーション, 入力検証, Zod, スキーマ, env 検証, 型強制, parse, safeParse, ランタイム境界.

The English summary is being prepared. Showing the original description.

See how to install

Files included (1)

  • SKILL.md1.9 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

Zod バリデーション

いつ使うか

  • API / Server Action の入力を受け取るとき。
  • 環境変数(process.env)を読むとき。
  • 外部 API や DB の応答を信用する前。

やること

  • ランタイム境界(入力・env・外部応答)に Zod スキーマを置く。
  • 失敗を例外にするか値で返すかを使い分ける(parse vs safeParse)。
  • env は起動時に 1 度だけ検証し、型付き設定オブジェクトとして公開する。
  • Zod の infer で TypeScript 型を導出し、二重定義を避ける。

守るルール

  • ✅ 入力・env・DB 応答は必ず Zod を通す。
  • ✅ ユーザー向け入力は safeParse でエラーを丁寧に返す。
  • ✅ env スキーマは server-only 側に置き、クライアント露出を防ぐ。
  • ❌ as キャストで検証を飛ばさない(unknown → Zod が正解)。
  • ❌ 同じ形を Zod と interface で二重管理しない(z.infer を使う)。

典型例(コード片)

// lib/env.ts — 起動時に env を検証
import { z } from 'zod';

const EnvSchema = z.object({
  MONGODB_URI: z.string().url(),
  AUTH_SECRET: z.string().min(32),
  NODE_ENV: z.enum(['development', 'test', 'production']),
});

export const env = EnvSchema.parse(process.env); // 失敗時は起動で落とす
export type Env = z.infer<typeof EnvSchema>;

アンチパターン

  • 入力を as MyType でキャストして検証した気になる。
  • env を直接 process.env.X! で参照し、欠落に実行時まで気づかない。
  • 型と検証ロジックがズレて、通るはずの値が弾かれる。

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

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.

The English summary is being prepared. Showing the original description.

Akira-Papa/claude-code-nextjs-mongo-template-16Updated May 24, 2026

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.

The English summary is being prepared. Showing the original description.

Akira-Papa/claude-code-nextjs-mongo-template-16Updated May 24, 2026

Use this skill when implementing sign-in, sessions, authorization checks, or protecting routes and Server Actions. Trigger words: 認証, ログイン, サインイン, セッション, 認可, 権限チェック, Better Auth, Auth.js, 保護, ミドルウェア, getSession.

The English summary is being prepared. Showing the original description.

Akira-Papa/claude-code-nextjs-mongo-template-16Updated May 24, 2026

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.

The English summary is being prepared. Showing the original description.

Akira-Papa/claude-code-nextjs-mongo-template-16Updated May 24, 2026

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.

The English summary is being prepared. Showing the original description.

Akira-Papa/claude-code-nextjs-mongo-template-16Updated May 24, 2026

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.

The English summary is being prepared. Showing the original description.

Akira-Papa/claude-code-nextjs-mongo-template-16Updated May 24, 2026

See all skills by Akira-Papa

Report a problem with this skill