{"library":"open-serverless-auth","title":"Open Serverless Auth Toolkit for Next.js","description":"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.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install open-serverless-auth"],"cli":null},"imports":["import { createAuthMiddleware } from 'open-serverless-auth';","import { getUserData } from 'open-serverless-auth';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { createAuthMiddleware, getUserData } from 'open-serverless-auth';\nimport { redirect } from 'next/navigation';\n\n// --- src/middleware.ts ---\nexport const middleware = createAuthMiddleware({\n  // The domain of your central auth hub, e.g., 'auth.yourdomain.com'\n  // Falls back to process.env.NEXT_PUBLIC_DOMAIN if not provided.\n  // domain: process.env.NEXT_PUBLIC_DOMAIN,\n\n  // For local development only: Bypasses auth and injects a dummy user.\n  // This is automatically ignored in production environments.\n  devBypassUser: {\n    id: \"local-dev-id\",\n    email: \"developer@example.com\",\n    role: \"ADMIN\",\n    rules: { customPermission: true }\n  }\n});\n\nexport const config = {\n  // Protect all routes except API routes, static assets, and favicon.ico\n  matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],\n};\n\n// --- src/app/dashboard/page.tsx (Server Component) ---\nexport default async function DashboardPage() {\n  const user = await getUserData();\n\n  if (!user) {\n    // Redirect unauthenticated users to a login page or an unauthorized page\n    redirect('/unauthorized');\n  }\n\n  return (\n    <div>\n      <h1>Welcome back, {user.email}!</h1>\n      <p>Your role: {user.role}</p>\n      <p>Permissions: {JSON.stringify(user.rules)}</p>\n    </div>\n  );\n}","lang":"typescript","description":"Demonstrates setting up Edge Middleware for authentication and retrieving user data in a Next.js Server Component.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}