跳到正文
cccskills
免费在 GitHub 公开

auth-better-auth

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

中文简介正在准备中。当前显示原文说明。

查看安装方法

包含的文件(1)

  • SKILL.md2.3 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

認証(Better Auth / Auth.js v5)

いつ使うか

  • ログイン/サインアップ・セッション管理を実装するとき。
  • ページや Server Action を「ログイン必須」「特定ロールのみ」に守るとき。

やること

  • 認証は Better Auth(または Auth.js v5)を採用し、設定は server-only に置く。
  • セッション取得は server 側のヘルパー(getSession/requireUser)に集約する。
  • 認証(誰か)と認可(何をしてよいか)を分けて両方チェックする。
  • 保護はレイアウト/ページの server 側と Server Action の両方で行う(クライアントだけに依存しない)。
  • セッションシークレットは .env.local、本番は環境変数。

守るルール

  • ✅ Server Action は冒頭で requireUser() → ロール検証の順。
  • ✅ セッション/トークンは httpOnly Cookie。クライアント JS から読ませない。
  • ✅ 認可ロジックは 1 箇所に集約し再利用する。
  • ❌ クライアント側の if (user) だけで保護した気にならない。
  • ❌ シークレット/トークンをクライアントへ返さない。

典型例(コード片)

// lib/auth.ts
import { headers } from 'next/headers';
import { auth } from '@/lib/auth-config'; // Better Auth インスタンス(server-only)

export async function requireUser() {
  const session = await auth.api.getSession({ headers: await headers() });
  if (!session) throw new Error('UNAUTHENTICATED');
  return { userId: session.user.id, role: session.user.role };
}

export async function requireAdmin() {
  const s = await requireUser();
  if (s.role !== 'admin') throw new Error('FORBIDDEN');
  return s;
}

アンチパターン

  • クライアントコンポーネントの表示制御だけで「保護」と考える。
  • 認証は確認するが認可(ロール/所有者)を見落とす。
  • セッション情報をログに出して漏らす。

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

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.

中文简介正在准备中。当前显示原文说明。

Akira-Papa/claude-code-nextjs-mongo-template-162026年5月24日 更新

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.

中文简介正在准备中。当前显示原文说明。

Akira-Papa/claude-code-nextjs-mongo-template-162026年5月24日 更新

bootstrap

免费

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.

中文简介正在准备中。当前显示原文说明。

Akira-Papa/claude-code-nextjs-mongo-template-162026年5月24日 更新

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.

中文简介正在准备中。当前显示原文说明。

Akira-Papa/claude-code-nextjs-mongo-template-162026年5月24日 更新

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.

中文简介正在准备中。当前显示原文说明。

Akira-Papa/claude-code-nextjs-mongo-template-162026年5月24日 更新

Use this skill when handling runtime errors, adding error.tsx or not-found.tsx, designing fallback UI, or deciding what to surface to users vs logs. Trigger words: エラー処理, error.tsx, not-found, 例外, フォールバック, エラーバウンダリ, try catch, ユーザー向けエラー, ログ.

中文简介正在准备中。当前显示原文说明。

Akira-Papa/claude-code-nextjs-mongo-template-162026年5月24日 更新

查看 Akira-Papa 的全部技能

报告此技能的问题