This package, `open-serverless-auth` (current version 0.2.0), provides a toolkit for integrating Next.js applications with a centralized Open Serverless Auth hub. It includes an Edge Middleware for protecting downstream applications by redirecting unauthorized users, and Server Action/Component helpers like `getUserData()` to retrieve authenticated user information. Its primary differentiator is simplifying centralized authentication architecture across subdomains using cross-subdomain cookies, abstracting away complex login UI development on client apps. It's designed to work seamlessly with Next.js App Router and assumes a peer dependency on `next` version 13 or higher. The current version suggests it's relatively new, likely in active development with potentially frequent updates, although a specific release cadence isn't stated. The core value proposition is enabling easy setup of a centralized authentication system, offloading authentication concerns from individual client applications.
npm install open-serverless-authVerified import paths — ran on the pinned version, not inferred.
Demonstrates setting up Edge Middleware for authentication and retrieving user data in a Next.js Server Component.
Rely on the library's built-in `NODE_ENV` check. If custom environment-specific bypasses are needed, implement them securely and independently, ensuring they are strictly isolated from production deployments.
Ensure your Next.js project is version 13 or newer and configured to use the App Router. Migrate existing Pages Router applications if necessary.
Carefully review and test your `matcher` array. The recommended pattern `/((?!api|_next/static|_next/image|favicon.ico).*)` typically covers most use cases by protecting all non-static, non-API routes. Adjust this pattern meticulously for any custom route requirements.
Set `process.env.NEXT_PUBLIC_DOMAIN` to the full domain of your auth hub (e.g., `auth.yourdomain.com`) in your Next.js application's environment variables, or explicitly pass the `domain` option to `createAuthMiddleware({ domain: 'auth.yourdomain.com' })`.Always implement a null check for the `user` object and handle the unauthenticated state, typically by redirecting the user to a login page or an unauthorized page, e.g., `if (!user) { redirect('/unauthorized'); }`.Ensure you are using `import { createAuthMiddleware } from 'open-serverless-auth';` and not `require()`. Verify that your `middleware.ts` file is correctly configured as an ESM module if not already default.