Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
sickn33 avatar

Nextjs Supabase Auth

  • 6k installs
  • 44k repo stars
  • Updated July 27, 2026
  • sickn33/antigravity-awesome-skills

nextjs-supabase-auth is an agent skill for Supabase Auth integration with Next.js App Router middleware, callbacks, and Server Actions.

About

The nextjs-supabase-auth skill provides expert Supabase Auth integration with Next.js App Router. Patterns cover createBrowserClient for client components and createServerClient with Next cookies for server contexts, avoiding insecure getSession() in favor of getUser() for JWT-verified checks. Middleware refreshes sessions and protects routes such as /dashboard with matcher exclusions for static assets. OAuth flows require app/auth/callback/route.ts to exchange codes via exchangeCodeForSession. Server Actions handle signIn, signOut, and signup with error handling plus revalidatePath to prevent stale cache. Server Components fetch the authenticated user before rendering protected pages. Validation checks flag browser clients in server code, missing callback routes, client-only protection flash, hardcoded redirect URLs, and auth calls without error handling. Delegation triggers route database work to supabase-backend, UI to frontend, and deployment to vercel-deployment for a full protected SaaS stack alongside stripe-integration.

  • Splits createBrowserClient and createServerClient with proper Next.js cookie adapters.
  • Middleware refreshes sessions and redirects unauthenticated users from protected routes.
  • OAuth requires auth callback route using exchangeCodeForSession before redirect.
  • Server Actions sign in and out with error handling and revalidatePath for fresh auth state.
  • Validation flags getSession misuse, missing middleware, and browser clients on the server.

Nextjs Supabase Auth by the numbers

  • 5,997 all-time installs (skills.sh)
  • +96 installs in the week ending Jul 28, 2026 (Skillselion tracking)
  • Ranked #128 of 4,386 Backend & APIs skills by installs in the Skillselion catalog
  • Security screen: LOW risk (skills.sh audit)
  • Data as of Jul 28, 2026 (Skillselion catalog sync)
At a glance

nextjs-supabase-auth capabilities & compatibility

Capabilities
browser and server supabase client setup with @s · middleware session refresh and protected route r · oauth callback route with exchangecodeforsession · server action signin, signout, and signup with r · server component getuser checks before rendering · validation rules against getsession, missing cal
Works with
supabase · vercel
Use cases
api development · frontend
Runs
Hosted SaaS
From the docs

What nextjs-supabase-auth says it does

Expert integration of Supabase Auth with Next.js App Router
SKILL.md
getSession() doesn't verify the JWT. Use getUser() for secure auth checks.
SKILL.md
Create middleware.ts to protect routes and refresh sessions
SKILL.md
npx skills add https://github.com/sickn33/antigravity-awesome-skills --skill nextjs-supabase-auth

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs6k
repo stars44k
Security audit3 / 3 scanners passed
Last updatedJuly 27, 2026
Repositorysickn33/antigravity-awesome-skills

How do I securely wire Supabase Auth into Next.js App Router with SSR clients, route protection, and OAuth callbacks?

Supabase Auth with Next.js App Router via SSR clients, middleware protection, OAuth callbacks, and Server Actions.

Who is it for?

Next.js App Router projects using Supabase Auth for login, OAuth, session refresh, and protected dashboards.

Skip if: Skip when the stack is not Next.js App Router with Supabase or when only database queries without auth are needed.

When should I use this skill?

User mentions supabase auth next, authentication next.js, login supabase, auth middleware, protected route, or session management.

What you get

Working Supabase auth with verified getUser checks, middleware-protected routes, OAuth callback handling, and cache-safe Server Actions.

  • lib/supabase/client.ts
  • auth middleware
  • auth callback routes

By the numbers

  • Declares 4 named capabilities: nextjs-auth, supabase-auth-nextjs, auth-middleware, auth-callback
  • Requires 2 prerequisite skills: nextjs-app-router and supabase-backend

Files

SKILL.mdMarkdownGitHub ↗

Next.js + Supabase Auth

Expert integration of Supabase Auth with Next.js App Router

Capabilities

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

Prerequisites

  • Required skills: nextjs-app-router, supabase-backend

Patterns

Supabase Client Setup

Create properly configured Supabase clients for different contexts

When to use: Setting up auth in a Next.js project

// lib/supabase/client.ts (Browser client) '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 (Server client) 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) }) }, }, } ) }

Auth Middleware

Protect routes and refresh sessions in middleware

When to use: You need route protection or session refresh

// 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) }) }, }, } )

// Refresh session if expired const { data: { user } } = await supabase.auth.getUser()

// Protect dashboard routes 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).*)'], }

Auth Callback Route

Handle OAuth callback and exchange code for session

When to use: Using OAuth providers (Google, GitHub, etc.)

// 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) }

Server Action Auth

Handle auth operations in Server Actions

When to use: Login, logout, or signup from Server Components

// 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('/') }

Get User in Server Component

Access the authenticated user in Server Components

When to use: Rendering user-specific content server-side

// 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>Welcome, {user.email}</h1> </div> ) }

Validation Checks

Using getSession() for Auth Checks

Severity: ERROR

Message: getSession() doesn't verify the JWT. Use getUser() for secure auth checks.

Fix action: Replace getSession() with getUser() for security-critical checks

OAuth Without Callback Route

Severity: ERROR

Message: Using OAuth but missing callback route at app/auth/callback/route.ts

Fix action: Create app/auth/callback/route.ts to handle OAuth redirects

Browser Client in Server Context

Severity: ERROR

Message: Browser client used in server context. Use createServerClient instead.

Fix action: Import and use createServerClient from @supabase/ssr

Protected Routes Without Middleware

Severity: WARNING

Message: No middleware.ts found. Consider adding middleware for route protection.

Fix action: Create middleware.ts to protect routes and refresh sessions

Hardcoded Auth Redirect URL

Severity: WARNING

Message: Hardcoded localhost redirect. Use origin for environment flexibility.

Fix action: Use window.location.origin or process.env.NEXT_PUBLIC_SITE_URL

Auth Call Without Error Handling

Severity: WARNING

Message: Auth operation without error handling. Always check for errors.

Fix action: Destructure { data, error } and handle error case

Auth Action Without Revalidation

Severity: WARNING

Message: Auth action without revalidatePath. Cache may show stale auth state.

Fix action: Add revalidatePath('/', 'layout') after auth operations

Client-Only Route Protection

Severity: WARNING

Message: Client-side route protection shows flash of content. Use middleware.

Fix action: Move protection to middleware.ts for better UX

Collaboration

Delegation Triggers

  • database|rls|queries|tables -> supabase-backend (Auth needs database layer)
  • route|page|component|layout -> nextjs-app-router (Auth needs Next.js patterns)
  • deploy|production|vercel -> vercel-deployment (Auth needs deployment config)
  • ui|form|button|design -> frontend (Auth needs UI components)

Full Auth Stack

Skills: nextjs-supabase-auth, supabase-backend, nextjs-app-router, vercel-deployment

Workflow:

1. Database setup (supabase-backend)
2. Auth implementation (nextjs-supabase-auth)
3. Route protection (nextjs-app-router)
4. Deployment config (vercel-deployment)

Protected SaaS

Skills: nextjs-supabase-auth, stripe-integration, supabase-backend

Workflow:

1. User authentication (nextjs-supabase-auth)
2. Customer sync (stripe-integration)
3. Subscription gating (supabase-backend)

Related Skills

Works well with: nextjs-app-router, supabase-backend

When to Use

  • User mentions or implies: supabase auth next
  • User mentions or implies: authentication next.js
  • User mentions or implies: login supabase
  • User mentions or implies: auth middleware
  • User mentions or implies: protected route
  • User mentions or implies: auth callback
  • User mentions or implies: session management

Limitations

  • Use this skill only when the task clearly matches the scope described above.
  • Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
  • Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.

Related skills

How it compares

Choose nextjs-supabase-auth over generic auth tutorials when you specifically need App Router SSR cookie patterns with Supabase rather than client-only or Pages Router setups.

FAQ

Why use getUser instead of getSession?

getSession does not verify the JWT; getUser performs secure auth checks for protected routes and server rendering.

What does OAuth require beyond the provider setup?

Add app/auth/callback/route.ts that calls exchangeCodeForSession on the code query param before redirecting.

How should Server Actions update auth state?

Check { data, error } on auth calls, then call revalidatePath on the layout and redirect after successful sign in or sign out.

Is Nextjs Supabase Auth safe to install?

skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.

Backend & APIsfrontendbackendintegrations

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.