RegisterLogin
DocsPricing
RegisterLogin
  • Getting Started
  • Introduction
  • Quick Start
  • SDKs
  • React
  • TypeScript
  • Next.js
  • Express
  • NestJS
  • Python
  • API Reference
  • Support and Resources
  • FAQ
  • Contact

Middleware

Next.js middleware for protecting routes and route groups with automatic authentication checks.


Overview

AuthSafe provides two middleware functions for route protection: createAuthMiddleware() for full route protection with redirects, and authMiddleware() for simple authentication check without enforcement. Both middleware functions work with Next.js Edge Runtime for optimal performance.


Basic Usage

import { createAuthMiddleware } from 'authsafe-nextjs/server';

export default createAuthMiddleware({
  authConfig: {
    clientId: process.env.AUTHSAFE_CLIENT_ID,
    domain: process.env.AUTHSAFE_DOMAIN,
  },
  protectedRoutes: ['/dashboard/:path*', '/settings/:path*'],
  publicRoutes: ['/'],
});

Best Practices
  • Always exclude static assets from matcher to avoid unnecessary processing
  • Use regex for pattern matching when protecting route groups
  • Public routes take precedence over protected routes for flexibility

AuthSafe

Product

HighlightFeatureIntegrationPricingFAQ

Company

AboutBlogContact

Developer

DashboardDocumentation

Legal

Terms & ConditionsPrivacyComplianceShippingCancellationAI

© 2026 AuthSafe. All rights reserved.

Valoramos su privacidad

Este sitio web utiliza cookies para análisis anónimos que nos ayudan a mejorar su experiencia. No se almacena ni comparte información personal. Puede permitir o rechazar el seguimiento analítico en cualquier momento. Consulte nuestra Política de Privacidad.

Usamos cookies para análisis anónimos. No se almacena información personal. Consulte nuestra Política de Privacidad.