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.

Nous respectons votre vie privée

Ce site utilise des cookies pour des analyses anonymes afin d'améliorer votre expérience. Aucune information personnelle n'est stockée ni partagée. Vous pouvez autoriser ou refuser le suivi analytique à tout moment. Consultez notre Politique de Confidentialité.

Nous utilisons des cookies pour des analyses anonymes. Aucune donnée personnelle n'est stockée. Consultez notre Politique de Confidentialité.