Communitygithub.com

ASoudy/AGS

Next.js App Router와 Supabase Auth를 전문적으로 통합합니다.

AGS란 무엇인가요?

이 스킬은 Next.js App Router 애플리케이션에 Supabase Auth를 손쉽게 통합할 수 있도록 설계된 전문 가이드입니다. 개발자는 브라우저 클라이언트, 서버 클라이언트, 미들웨어 등 다양한 컨텍스트에 맞게 Supabase 클라이언트를 설정하는 방법을 배울 수 있습니다. 또한 OAuth 콜백 처리, 서버 액션에서의 인증 작업, 서버 컴포넌트에서 인증된 사용자 정보 가져오기 등 실제 프로젝트에서 자주 필요한 패턴을 제공합니다. 이 스킬은 Next.js App Router와 Supabase를 함께 사용하는 프로젝트에서 보안과 생산성을 높이는 데 필수적입니다.

지원 대상~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ASoudy/AGS/tree/HEAD/AGAS/plugins/antigravity-awesome-skills-claude/skills/nextjs-supabase-auth

즐겨 사용하는 AI에게 물어보기

이 에이전트 스킬이 미리 로드된 새 채팅을 엽니다.

문서

Next.js + Supabase Auth

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() 사용

심각도: 오류

메시지: 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.

ASoudy/AGS

Advanced JavaScript animation library skill for creating complex, high-performance web animations.

ASoudy/AGS

Astropy is the core Python package for astronomy, providing essential functionality for astronomical research and data analysis.

ASoudy/AGS

Build content-focused websites with Astro — zero JS by default, islands architecture, multi-framework components, and Markdown/MDX support.

ASoudy/AGS

One sentence - what this skill does and when to invoke it

ASoudy/AGS

Audit and fix animation performance issues including layout thrashing, compositor properties, scroll-linked motion, and blur effects. Use when animations stutter, transitions jank, or reviewing CSS/JS animation performance.

ASoudy/AGS

Internationalization and localization patterns. Detecting hardcoded strings, managing translations, locale files, RTL support.

ASoudy/AGS

Pull a YouTube video transcript into a queryable markdown vault with yt-dlp subtitle discovery, VTT cleanup, metadata frontmatter, and capture-seed stubs.

ASoudy/AGS

Expert in building portfolios that actually land jobs and clients - not just showing work, but creating memorable experiences. Covers developer portfolios, designer portfolios, creative portfolios, and portfolios that convert visitors into opportunities.

ASoudy/AGS

Generates high-converting Next.js/React landing pages with Tailwind CSS. Uses PAS, AIDA, and BAB frameworks for optimized copy/components (Heroes, Features, Pricing). Focuses on Core Web Vitals/SEO.

ASoudy/AGS

AI-powered animation tool for creating motion in logos, UI, icons, and social media assets.

ASoudy/AGS

CRITICAL: Use for Makepad animation system. Triggers on: makepad animation, makepad animator, makepad hover, makepad state, makepad transition, "from: { all: Forward", makepad pressed, makepad 动画, makepad 状态, makepad 过渡, makepad 悬停效果

ASoudy/AGS

Comprehensive patterns for Next.js 14+ App Router architecture, Server Components, and modern full-stack React development.

ASoudy/AGS

Next.js App Router principles. Server Components, data fetching, routing patterns.

ASoudy/AGS

React and Next.js 14+ application development with App Router, Server Components, TypeScript, Tailwind CSS, and modern frontend patterns.

ASoudy/AGS

Best practices for Remotion - Video creation in React

ASoudy/AGS

Generate walkthrough videos from Stitch projects using Remotion with smooth transitions, zooming, and text overlays

ASoudy/AGS

Seek and analyze video content using Memories.ai Large Visual Memory Model for persistent video intelligence

ASoudy/AGS

Writes complete, structured landing pages optimized for SEO ranking, AEO citation, and visitor conversion. Activate when the user wants to write or generate a landing page for a product, service, or offer.

ASoudy/AGS

Three.js animation - keyframe animation, skeletal animation, morph targets, animation mixing. Use when animating objects, playing GLTF animations, creating procedural motion, or blending animations.

ASoudy/AGS

Skill for discovering and researching autonomous AI agents, tools, and ecosystems using the AgentFolio directory.

관련 스킬