Communitygithub.com

Anhvu1107/all-agent-skill

Next.js Supabase Authの専門家による統合(App Router対応)リクエストが一致した場合、常にこれを使用します。

all-agent-skill とは?

このスキルは、Next.js App RouterにSupabase Authを専門的に統合するためのガイドです。開発者は、ブラウザクライアント、サーバークライアント、ミドルウェア、OAuthコールバックルート、サーバーアクション、サーバーコンポーネントでのユーザー取得など、認証に関するすべてのパターンを習得できます。このスキルは、`nextjs-app-router` や `supabase-backend` などの他のスキルと連携して動作し、完全な認証スタックを提供します。また、`getSession()` の代わりに `getUser()` を使用するなどの検証チェックや、ミドルウェアなしでルートを保護する場合の警告も含まれています。このスキルは、Next.jsプロジェクトでSupabase Authをセットアップし、安全で効率的な認証を実現したいときに使用します。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Anhvu1107/all-agent-skill/tree/HEAD/.agent/skills/nextjs-supabase-auth

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

Next.js + Supabase Auth

選択的読み取りルール

以下から開始します:

  • references/senior-master-standard.md
  • references/usage-routing.md
  • references/quality-checklist.md

次に、ユーザーの実際のタスクに一致する継承されたドキュメント、スクリプト、アセット、または例のみをロードします。

Next.js App Router と Supabase Auth の専門家による統合

機能

  • nextjs-auth
  • supabase-auth-nextjs
  • auth-middleware
  • auth-callback

前提条件

  • 必要なスキル: nextjs-app-router, supabase-backend

パターン

Supabase クライアントのセットアップ

さまざまなコンテキストに対応する適切に構成された Supabase クライアントを作成する

使用するタイミング: Next.js プロジェクトで認証を設定する場合

// lib/supabase/client.ts (ブラウザクライアント)
'use client'
import { createBrowserClient } from '@supabase/ssr'

export function createClient() {
  return createBrowserClient(
    process.env.NEXT_PUBLIC_SUPABASE_URL!,
    process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
  )
}

// lib/supabase/server.ts (サーバークライアント)
import { createServerClient } from '@supabase/ssr'
import { cookies } from 'next/headers'

export async function createClient() {
  const cookieStore = await cookies()
  return createServerClient(
    process.env.NEXT_PUBLIC_SUPABASE_URL!,
    process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
    {
      cookies: {
        getAll() {
          return cookieStore.getAll()
        },
        setAll(cookiesToSet) {
          cookiesToSet.forEach(({ name, value, options }) => {
            cookieStore.set(name, value, options)
          })
        },
      },
    }
  )
}

認証ミドルウェア

ミドルウェアでルートを保護し、セッションを更新する

使用するタイミング: ルート保護またはセッション更新が必要な場合

// middleware.ts
import { createServerClient } from '@supabase/ssr'
import { NextResponse, type NextRequest } from 'next/server'

export async function middleware(request: NextRequest) {
  let response = NextResponse.next({ request })

  const supabase = createServerClient(
    process.env.NEXT_PUBLIC_SUPABASE_URL!,
    process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
    {
      cookies: {
        getAll() {
          return request.cookies.getAll()
        },
        setAll(cookiesToSet) {
          cookiesToSet.forEach(({ name, value, options }) => {
            response.cookies.set(name, value, options)
          })
        },
      },
    }
  )

  // 期限切れのセッションを更新
  const { data: { user } } = await supabase.auth.getUser()

  // ダッシュボードルートを保護
  if (request.nextUrl.pathname.startsWith('/dashboard') && !user) {
    return NextResponse.redirect(new URL('/login', request.url))
  }

  return response
}

export const config = {
  matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
}

認証コールバックルート

OAuth コールバックを処理し、コードをセッションと交換する

使用するタイミング: OAuth プロバイダー(Google、GitHub など)を使用する場合

// app/auth/callback/route.ts
import { createClient } from '@/lib/supabase/server'
import { NextResponse } from 'next/server'

export async function GET(request: Request) {
  const { searchParams, origin } = new URL(request.url)
  const code = searchParams.get('code')
  const next = searchParams.get('next') ?? '/'

  if (code) {
    const supabase = await createClient()
    const { error } = await supabase.auth.exchangeCodeForSession(code)
    if (!error) {
      return NextResponse.redirect(`${origin}${next}`)
    }
  }

  return NextResponse.redirect(`${origin}/auth/error`)
}

サーバーアクション認証

サーバーアクションで認証操作を処理する

使用するタイミング: サーバーコンポーネントからログイン、ログアウト、またはサインアップを行う場合

// app/actions/auth.ts
'use server'
import { createClient } from '@/lib/supabase/server'
import { redirect } from 'next/navigation'
import { revalidatePath } from 'next/cache'

export async function signIn(formData: FormData) {
  const supabase = await createClient()
  const { error } = await supabase.auth.signInWithPassword({
    email: formData.get('email') as string,
    password: formData.get('password') as string,
  })

  if (error) {
    return { error: error.message }
  }

  revalidatePath('/', 'layout')
  redirect('/dashboard')
}

export async function signOut() {
  const supabase = await createClient()
  await supabase.auth.signOut()
  revalidatePath('/', 'layout')
  redirect('/')
}

サーバーコンポーネントでユーザーを取得する

サーバーコンポーネントで認証済みユーザーにアクセスする

使用するタイミング: サーバーサイドでユーザー固有のコンテンツをレンダリングする場合

// app/dashboard/page.tsx
import { createClient } from '@/lib/supabase/server'
import { redirect } from 'next/navigation'

export default async function DashboardPage() {
  const supabase = await createClient()
  const { data: { user } } = await supabase.auth.getUser()

  if (!user) {
    redirect('/login')
  }

  return (
    <div>
      <h1>ようこそ, {user.email}</h1>
    </div>
  )
}

検証チェック

認証チェックに getSession() を使用する

重大度: ERROR

メッセージ: getSession() は JWT を検証しません。安全な認証チェックには getUser() を使用してください。

修正方法: セキュリティ上重要なチェックでは getSession() を getUser() に置き換えてください

OAuth コールバックルートがない

重大度: ERROR

メッセージ: OAuth を使用していますが、app/auth/callback/route.ts にコールバックルートがありません

修正方法: OAuth リダイレクトを処理するために app/auth/callback/route.ts を作成してください

サーバーコンテキストでのブラウザクライアント

重大度: ERROR

メッセージ: サーバーコンテキストでブラウザクライアントが使用されています。代わりに createServerClient を使用してください。

修正方法: @supabase/ssr から createServerClient をインポートして使用してください

ミドルウェアなしの保護ルート

重大度: WARNING

メッセージ: middleware.ts が見つかりません。ルート保護のためにミドルウェアを追加することを検討してください。

修正方法: ルートを保護しセッションを更新するために middleware.ts を作成してください

ハードコードされた認証リダイレクト URL

重大度: WARNING

メッセージ: localhost リダイレクトがハードコードされています。環境の柔軟性のために origin を使用してください。

修正方法: window.location.origin または process.env.NEXT_PUBLIC_SITE_URL を使用してください

エラーハンドリングなしの認証呼び出し

重大度: WARNING

メッセージ: エラーハンドリングなしの認証操作です。常にエラーを確認してください。

修正方法: { data, error } を分割代入し、エラーケースを処理してください

再検証なしの認証アクション

重大度: WARNING

メッセージ: revalidatePath なしの認証アクションです。キャッシュに古い認証状態が表示される可能性があります。

修正方法: 認証操作の後に revalidatePath('/', 'layout') を追加してください

クライアントのみのルート保護

重大度: WARNING

メッセージ: クライアントサイドのルート保護ではコンテンツが一瞬表示されます。ミドルウェアを使用してください。

修正方法: より良い UX のために保護を middleware.ts に移動してください

コラボレーション

委任トリガー

  • database|rls|queries|tables -> supabase-backend (認証はデータベース層を必要とします)
  • route|page|component|layout -> nextjs-app-router (認証は Next.js パターンを必要とします)
  • deploy|production|vercel -> vercel-deployment (認証はデプロイ設定を必要とします)
  • ui|form|button|design -> frontend (認証は UI コンポーネントを必要とします)

完全な認証スタック

スキル: nextjs-supabase-auth, supabase-backend, nextjs-app-router, vercel-deployment

ワークフロー:

1. データベースのセットアップ (supabase-backend)
2. 認証の実装 (nextjs-supabase-auth)
3. ルートの保護 (nextjs-app-router)
4. デプロイ設定 (vercel-deployment)

保護された SaaS

スキル: nextjs-supabase-auth, stripe-integration, supabase-backend

ワークフロー:

1. ユーザー認証 (nextjs-supabase-auth)
2. 顧客同期 (stripe-integration)
3. サブスクリプション制御 (supabase-backend)

関連スキル

以下のスキルと連携して動作します: nextjs-app-router, supabase-backend

使用するタイミング

  • ユーザーが言及または示唆した場合: supabase auth next
  • ユーザーが言及または示唆した場合: authentication next.js
  • ユーザーが言及または示唆した場合: login supabase
  • ユーザーが言及または示唆した場合: auth middleware
  • ユーザーが言及または示唆した場合: protected route
  • ユーザーが言及または示唆した場合: auth callback
  • ユーザーが言及または示唆した場合: session management

制限事項

  • このスキルは、タスクが上記のスコープに明確に一致する場合にのみ使用してください。
  • 出力を、環境固有の検証、テスト、または専門家によるレビューの代わりとして扱わないでください。
  • 必要な入力、権限、安全性の境界、または成功基準が欠落している場合は、一時停止して明確化を求めてください。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches 007: Security audit, hardening, threat modeling (STRIDE/PASTA), Red/Blue Team, OWASP checks, code review, incident response, and infrastructure security for any project.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Agentfolio: Skill for discovering and researching autonomous AI agents, tools, and ecosystems using the AgentFolio directory.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Animejs Animation: Advanced JavaScript animation library skill for creating complex, high-performance web animations.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Astropy: Astropy is the core Python package for astronomy, providing essential functionality for astronomical research and data analysis.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Astro: Build content-focused websites with Astro — zero JS by default, islands architecture, multi-framework components, and Markdown/MDX support.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Emotional ARC Designer: One sentence - what this skill does and when to invoke it

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Fixing Motion Performance: Audit and fix animation performance issues including layout thrashing, compositor properties, scroll-linked motion, and blur effects.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches I18n Localization: Internationalization and localization patterns.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Interactive Portfolio: Expert in building portfolios that actually land jobs and clients - not just showing work, but creating memorable experiences.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches JQ: Expert jq usage for JSON querying, filtering, transformation, and pipeline integration.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Landing Page Generator: Generates high-converting Next.js/React landing pages with Tailwind CSS.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches LEX: Centralized ''Truth Engine'' for cross-jurisdictional legal context (US, EU, CA) and contract scaffolding.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Magic Animator: AI-powered animation tool for creating motion in logos, UI, icons, and social media assets.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Makepad Animation: CRITICAL: Use for Makepad animation system.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Nextjs APP Router Patterns: Comprehensive patterns for Next.js 14+ App Router architecture, Server Components, and modern full-stack React development.

Anhvu1107/all-agent-skill

ALWAYS use this when the user mentions Nextjs Best Practices, asks to build, debug, review, document, automate, test, configure, migrate, or make decisions in this domain, or the task clearly depends on Nextjs Best Practices; scope: Next.js App Router principles. Apply the bundled workflow, references, scripts, Senior Master standard, and Codex strict review gate before final output.

Anhvu1107/all-agent-skill

description: ALWAYS use this when the work is specifically about modern Next.js or React architecture, data flow, rendering strategy, routing, or performance-sensitive frontend behavior.

Anhvu1107/all-agent-skill

ALWAYS use this when the task involves reading, extracting, splitting, merging, rotating, creating, validating, OCR-ing, form-filling, or otherwise producing or modifying PDF files.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches React Nextjs Development: React and Next.js 14+ application development with App Router, Server Components, TypeScript, Tailwind CSS, and modern frontend patterns.

Anhvu1107/all-agent-skill

ALWAYS use this when working with Remotion code, video compositions, rendering logic, timing, media assets, or React-based motion workflows.

関連スキル