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.