Communitygithub.com

Anhvu1107/all-agent-skill

通用於 Next.js 與 Supabase Auth 整合的專家技能,專門處理與 Next.js App Router 搭配的 Supabase 身分驗證。

all-agent-skill 是什麼?

此技能專為 AI 代理設計,用於在 Next.js 專案中整合 Supabase Auth,特別專注於 App Router 架構。它提供了一系列模式,包括瀏覽器端與伺服器端的 Supabase 客戶端建立、認證中介軟體(middleware)設定、OAuth 回呼路由處理、伺服器動作中的認證操作,以及在伺服器元件中取得使用者資訊。此技能支援 nextjs-app-router 和 supabase-backend 技能,並透過觸發機制與它們協作,實現完整的認證流程。此外,它還包含了驗證檢查清單,能檢測常見錯誤(如使用 getSession() 而非 getUser()、缺少回呼路由、在伺服器環境中使用瀏覽器客戶端等),並提供修復建議。透過遵循這些模式與驗證規則,AI 代理能產出安全、可維護的認證程式碼。

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

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Next.js + Supabase Auth

選擇性閱讀規則

從以下文件開始:

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

然後只載入與使用者實際任務相符的繼承文件、腳本、資產或範例。

專業整合 Supabase Auth 與 Next.js App Router

能力

  • 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() 進行認證檢查

嚴重性:錯誤

訊息:getSession() 不會驗證 JWT。請使用 getUser() 進行安全的認證檢查。

修正動作:將 getSession() 替換為 getUser() 以進行安全性關鍵的檢查

缺少 OAuth 回呼路由

嚴重性:錯誤

訊息:使用 OAuth 但缺少 app/auth/callback/route.ts 回呼路由

修正動作:建立 app/auth/callback/route.ts 來處理 OAuth 重新導向

在伺服器環境中使用瀏覽器客戶端

嚴重性:錯誤

訊息:在伺服器環境中使用了瀏覽器客戶端。請改用 createServerClient。

修正動作:從 @supabase/ssr 匯入並使用 createServerClient

沒有中介軟體的受保護路由

嚴重性:警告

訊息:未找到 middleware.ts。建議新增中介軟體以保護路由。

修正動作:建立 middleware.ts 來保護路由並重新整理工作階段

硬編碼的認證重新導向 URL

嚴重性:警告

訊息:硬編碼了 localhost 重新導向。請使用 origin 以獲得環境靈活性。

修正動作:使用 window.location.origin 或 process.env.NEXT_PUBLIC_SITE_URL

缺少錯誤處理的認證呼叫

嚴重性:警告

訊息:認證操作缺少錯誤處理。請務必檢查錯誤。

修正動作:解構 { data, error } 並處理錯誤情況

缺少重新驗證的認證動作

嚴重性:警告

訊息:認證動作缺少 revalidatePath。快取可能顯示過時的認證狀態。

修正動作:在認證操作後新增 revalidatePath('/', 'layout')

僅限客戶端的路由保護

嚴重性:警告

訊息:客戶端路由保護會顯示內容閃爍。請使用中介軟體。

修正動作:將保護邏輯移至 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.

相關技能