{"library":"next-lite-auth","title":"Lightweight JWT Auth for Next.js","description":"next-lite-auth is a lightweight, JWT-based authentication solution for Next.js applications, designed specifically for scenarios where a full database or third-party auth service is overkill. It uses static JSON for user management, loaded via environment variables, eliminating the need for database setup. The current stable version is 0.2.6. Release cadence appears to be iterative and feature-driven within the 0.x range, indicating active development. Its primary differentiators are its zero-database approach, ease of setup, and a built-in login UI, making it suitable for MVPs, internal tools, demos, and educational projects. It explicitly states it is not recommended for production environments requiring robust security or scalability, instead catering to rapid development and OSS projects where authentication can be easily toggled via environment variables.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install next-lite-auth"],"cli":null},"imports":["import { createLiteAuth } from 'next-lite-auth';","import { usersFromEnv } from 'next-lite-auth';","import { LiteAuthProvider } from 'next-lite-auth/client';","import { useLiteAuth } from 'next-lite-auth/client';","import { handlers } from '@/auth';","import { middleware } from '@/auth';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { createLiteAuth, usersFromEnv } from \"next-lite-auth\";\nimport { LiteAuthProvider } from \"next-lite-auth/client\";\nimport { cookies } from 'next/headers';\n\n// --- 1. Create auth.ts at your project root ---\n// auth.ts (server-side)\nexport const { handlers, middleware, getUserFromCookies } = createLiteAuth({\n  users: usersFromEnv(),\n  jwtSecret: process.env.LITE_AUTH_SECRET ?? 'fallback-secret-for-dev',\n  enabled: process.env.LITE_AUTH_ENABLED !== \"false\",\n});\n\n// .env.local example\n// LITE_AUTH_SECRET=your-random-secret-here\n// LITE_AUTH_ENABLED=true\n// LITE_AUTH_USERS=[{\"email\":\"admin@example.com\",\"password\":\"secret\",\"role\":\"admin\",\"name\":\"Admin\"}]\n\n// --- 2. Add one route file ---\n// app/api/auth/[...liteauth]/route.ts (API Route)\n// import { handlers } from \"@/auth\"; // Assuming '@/auth' resolves to the auth.ts file\n// export const { GET, POST } = handlers;\n\n// --- 3. Wrap root layout ---\n// components/auth-provider-wrapper.tsx (Client Component)\n\"use client\";\nexport function AuthProvider({ children }: { children: React.ReactNode }) {\n  return (\n    <LiteAuthProvider protect={[\"/dashboard\", \"/settings\"]} appName=\"My Next App\">\n      {children}\n    </LiteAuthProvider>\n  );\n}\n\n// app/layout.tsx (Server Component)\n// import { AuthProvider } from \"@/components/auth-provider-wrapper\";\n// export default function RootLayout({ children }: { children: React.ReactNode }) {\n//   return (\n//     <html>\n//       <body>\n//         <AuthProvider>{children}</AuthProvider>\n//       </body>\n//     </html>\n//   );\n// }\n\n// Example of server-side usage outside middleware/API routes\nasync function getServerSideUser() {\n  const user = await getUserFromCookies(cookies());\n  console.log('Server-side user:', user?.email);\n}\n\n// Call the function (e.g., in a Server Component or route handler)\ngetServerSideUser();","lang":"typescript","description":"This quickstart demonstrates the core 3-step setup: initializing auth utilities with environment variables, exposing API handlers, wrapping the application with the client-side provider, and an example of server-side user retrieval.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}