Skip to content
Back to skills

Collection

ASecurity

NextAuth.js v5の設定とカスタマイズパターン。 プロバイダー設定、アダプター統合、セッション戦略、 コールバックカスタマイズ、型安全性の確保を提供。 📚 リソース参照: このスキルには以下のリソースが含まれています。 必要に応じて該当するリソースを参照してください: - `.claude/skills/nextauth-patterns/resources/provider-configurations.md`: NextAuth.js Provider Configurations - `.claude/skills/nextauth-patterns/resources/session-callbacks-guide.md`: NextAuth.js Session Callbacks Guide - `.claude/skills/nextauth-patterns/scripts/validate-nextauth-config.mjs`: NextAuth.js設定ファイルの妥当性検証とプロバイダー設定・コールバック実装の検査スクリプト - `.cla...

  • 24 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 8, 2026
securitytypescriptgobashnextjsnodegitapidatabase

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 21 files and shows the line behind each finding

Scanned September 8, 2026

npx -y skills add mattnigh/skills_collection --skill collection --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Collection?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Collection
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/mattnigh-collection-90bc68d9/badge)](https://www.skillsdirectory.com/skills/mattnigh-collection-90bc68d9)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: .claude/skills/nextauth-patterns/SKILL.md
description: |
  NextAuth.js v5の設定とカスタマイズパターン。
  プロバイダー設定、アダプター統合、セッション戦略、
  コールバックカスタマイズ、型安全性の確保を提供。

  📚 リソース参照:
  このスキルには以下のリソースが含まれています。
  必要に応じて該当するリソースを参照してください:

  - `.claude/skills/nextauth-patterns/resources/provider-configurations.md`: NextAuth.js Provider Configurations
  - `.claude/skills/nextauth-patterns/resources/session-callbacks-guide.md`: NextAuth.js Session Callbacks Guide
  - `.claude/skills/nextauth-patterns/scripts/validate-nextauth-config.mjs`: NextAuth.js設定ファイルの妥当性検証とプロバイダー設定・コールバック実装の検査スクリプト
  - `.claude/skills/nextauth-patterns/templates/nextauth-config-template.ts`: Google/GitHub OAuth統合・Drizzleアダプター・JWT/Databaseセッション戦略を含むauth.ts設定テンプレート

  使用タイミング:
  - NextAuth.jsの初期設定時
  - OAuth 2.0プロバイダー統合時
  - セッション戦略(JWT/Database)の実装時
  - カスタムページ・コールバックの実装時
  - Drizzleアダプター統合時

  関連スキル:
  - `.claude/skills/oauth2-flows/SKILL.md` - OAuth 2.0基礎
  - `.claude/skills/session-management/SKILL.md` - セッション戦略
  - `.claude/skills/rbac-implementation/SKILL.md` - セッションへのロール統合

  Use when implementing NextAuth.js, configuring authentication providers,
  or customizing authentication flows in Next.js applications.

version: 1.0.0
---

# NextAuth.js Patterns

## スキル概要

**コアドメイン**:

- NextAuth.js v5設定
- プロバイダー設定
- アダプター統合
- セッションコールバック

## 基本設定

### auth.ts設定

```typescript
import NextAuth from "next-auth";
import Google from "next-auth/providers/google";
import { DrizzleAdapter } from "@auth/drizzle-adapter";
import { db } from "@/infrastructure/database";

export const { handlers, auth, signIn, signOut } = NextAuth({
  adapter: DrizzleAdapter(db),
  providers: [
    Google({
      clientId: process.env.GOOGLE_CLIENT_ID!,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
    }),
  ],
  session: {
    strategy: "jwt", // or 'database'
    maxAge: 30 * 24 * 60 * 60, // 30日
  },
  callbacks: {
    async jwt({ token, user }) {
      if (user) {
        token.role = user.role;
      }
      return token;
    },
    async session({ session, token }) {
      if (token) {
        session.user.role = token.role;
      }
      return session;
    },
  },
});
```

### Route Handler設定

```typescript
// app/api/auth/[...nextauth]/route.ts
import { handlers } from "@/auth";

export const { GET, POST } = handlers;
```

## プロバイダー設定

### Google OAuth 2.0

```typescript
import Google from "next-auth/providers/google";

Google({
  clientId: process.env.GOOGLE_CLIENT_ID!,
  clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
  authorization: {
    params: {
      scope: "openid email profile",
      prompt: "select_account", // アカウント選択強制
    },
  },
});
```

### GitHub OAuth 2.0

```typescript
import GitHub from "next-auth/providers/github";

GitHub({
  clientId: process.env.GITHUB_CLIENT_ID!,
  clientSecret: process.env.GITHUB_CLIENT_SECRET!,
  authorization: {
    params: {
      scope: "read:user user:email",
    },
  },
});
```

## アダプター統合

### Drizzle Adapter

```typescript
import { DrizzleAdapter } from "@auth/drizzle-adapter";
import { db } from "@/infrastructure/database";

export const { handlers, auth } = NextAuth({
  adapter: DrizzleAdapter(db),
  // 必須テーブル: users, accounts, sessions, verificationTokens
});
```

## セッションコールバック

### ロール情報の追加

```typescript
callbacks: {
  async jwt({ token, user, trigger }) {
    // 初回ログイン時
    if (user) {
      token.role = user.role;
      token.userId = user.id;
    }

    // セッション更新時
    if (trigger === 'update') {
      const updatedUser = await db.users.findOne({ id: token.userId });
      token.role = updatedUser.role;
    }

    return token;
  },

  async session({ session, token }) {
    session.user.id = token.userId;
    session.user.role = token.role;
    return session;
  },
}
```

## リソース参照

```bash
cat .claude/skills/nextauth-patterns/resources/provider-configurations.md
cat .claude/skills/nextauth-patterns/resources/adapter-integration.md
```

## テンプレート参照

```bash
cat .claude/skills/nextauth-patterns/templates/nextauth-config-template.ts
```

## スクリプト実行

```bash
node .claude/skills/nextauth-patterns/scripts/validate-nextauth-config.mjs auth.ts
```

## 判断基準

- [ ] プロバイダーは正しく設定されているか?
- [ ] セッション戦略は非機能要件と整合しているか?
- [ ] セッションにロール情報が含まれているか?
- [ ] 型安全性は保証されているか?

## ベストプラクティス

1. **JWT戦略**: スケーラブル、ステートレス
2. **Database戦略**: セキュア、即座無効化可能
3. **型拡張**: next-auth.d.tsで型定義拡張
4. **環境変数**: シークレット管理

## バージョン履歴

| バージョン | 日付       | 変更内容                              |
| ---------- | ---------- | ------------------------------------- |
| 1.0.0      | 2025-11-26 | 初版リリース - NextAuth.js v5パターン |

Files in this skill

  • 0Chan-smc__claude-code-workflow-lab__claude__skills__frontend-dev-guidelines__SKILL.md15.1 KB
  • 17hz__nextjs-template__claude__skills__example-skill__SKILL.md316 B
  • 1ambda__dataops-platform__claude__skills__context-synthesis__SKILL.md3.5 KB
  • 1natsu172__dotfiles__claude__skills__git-analysis__SKILL.md5.4 KB
  • 1natsu172__dotfiles__claude__skills__github-pr-best-practices__SKILL.md7.7 KB
  • 23Maestro__prospect-pipeline__claude__skills__npid-fastapi-skill.md26.1 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-code-javascript__SKILL.md15.7 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-code-python__SKILL.md17.5 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-expression-syntax__SKILL.md9.4 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-mcp-tools-expert__SKILL.md12.5 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-node-configuration__SKILL.md16.6 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-workflow-patterns__SKILL.md11.2 KB
  • 3x-Projetos__claude-memory-framework__claude__skills__scientist__SKILL.md14.8 KB
  • 5MinFutures__futures-arena__claude__skills__migration-tracker__SKILL.md16.2 KB
  • 5MinFutures__futures-arena__claude__skills__planning-guidelines__SKILL.md11.8 KB
  • 92Bilal26__TaskPilotAI__claude__skills__assessment-builder__SKILL.md17.5 KB
  • 92Bilal26__TaskPilotAI__claude__skills__book-scaffolding__SKILL.md19.1 KB
  • 92Bilal26__TaskPilotAI__claude__skills__code-validation-sandbox__SKILL.md6.2 KB
  • 92Bilal26__TaskPilotAI__claude__skills__exercise-designer__SKILL.md18.1 KB
  • 92Bilal26__TaskPilotAI__claude__skills__learning-objectives__SKILL.md24.5 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in security →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.