nextjs-supabase-auth

Integrate Supabase authentication into Next.js App Router with middleware token refresh.

1|Updated Apr 13, 2026
One-click install
npx skills add https://github.com/Inteligentsensingsolutions/tdd-dev-workflow --skill nextjs-supabase-auth-inteligentsensingsolutions
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: nextjs-supabase-auth
Source: https://github.com/Inteligentsensingsolutions/tdd-dev-workflow/tree/main/skills/nextjs-supabase-auth
Command: npx skills add https://github.com/Inteligentsensingsolutions/tdd-dev-workflow --skill nextjs-supabase-auth-inteligentsensingsolutions

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Provides a consistent, secure pattern for integrating Supabase authentication into Next.js App Router applications, addressing common pitfalls like stale tokens, client-only session checks, and deprecated helper libraries.

Core Features & Use Cases

  • Three runtime clients: Distinct browser, server, and middleware clients to ensure correct cookie handling and token propagation across client components, server components, and middleware.
  • Middleware token refresh: Centralized middleware flow to refresh tokens and redirect unauthenticated users to login or authenticated users away from login.
  • Server-side validation and protection: Use server-side session validation and protected layouts to prevent spoofed sessions and enforce role-based access control combined with RLS.
  • Auth callbacks and flows: Patterns for OAuth and magic link callback handling, server actions for sign in, sign up, and password reset, and guidance for environment configuration.
  • Use case: Protect an App Router dashboard with server-side checks, refresh tokens in middleware, and use server actions for authentication mutations to avoid exposing sensitive flows to the client.

Quick Start

Use nextjs-supabase-auth to implement server-side Supabase authentication with middleware token refresh and protected App Router routes.

Frequently Asked Questions about nextjs-supabase-auth

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement Supabase authentication in Next.js App Router with server-side session validation?

To implement Supabase authentication in Next.js App Router, use separate browser, server, and middleware clients for correct cookie handling and token propagation. Validate sessions server-side via getUser and apply protected layouts to enforce access control.

What's the best way to refresh Supabase auth tokens in Next.js middleware?

The best way to refresh Supabase auth tokens in Next.js middleware is using a centralized middleware flow. This approach refreshes tokens automatically and redirects unauthenticated users to login or authenticated users away from login pages.

How do I handle OAuth and magic link callbacks with Supabase in a Next.js App Router project?

Handle OAuth and magic link callbacks with Supabase by implementing specific callback route patterns in your Next.js App Router project. These patterns manage authentication redirects and establish secure server-side sessions.

Do I need separate Supabase clients for browser, server, and middleware in Next.js SSR?

Yes, you need separate browser, server, and middleware Supabase clients in Next.js SSR. Distinct clients ensure correct cookie handling and token propagation across client components, server components, and middleware.

How do I use server actions for Supabase auth mutations like sign in and password reset?

Use server actions for Supabase auth mutations to handle sign in, sign up, and password reset securely. This pattern avoids exposing sensitive authentication flows to the client by executing mutations server-side.

Why should I validate Supabase sessions server-side instead of using client-only checks in Next.js?

Validate Supabase sessions server-side to prevent spoofed sessions and enforce role-based access control combined with Row Level Security. Client-only checks risk exposing authentication state to manipulation and bypass.