{"_id":"@archlast/sdk-next","name":"@archlast/sdk-next","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.1":{"name":"@archlast/sdk-next","version":"0.1.1","description":"Archlast SDK for Next.js with SSR support","license":"MIT","repository":{"type":"git","url":"git+https://github.com/algochad/archlast-sync.git"},"type":"module","main":"./dist/index.cjs","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"},"./auth":{"types":"./dist/auth/index.d.ts","import":"./dist/auth/index.js","require":"./dist/auth/index.cjs"},"./react":{"types":"./dist/react.d.ts","import":"./dist/react.js","require":"./dist/react.cjs"}},"scripts":{"build":"tsup","prepublishOnly":"npm run build","test":"bun test","format":"prettier --write \"**/*.{ts,tsx,js,jsx,json,md}\"","format:check":"prettier --check \"**/*.{ts,tsx,js,jsx,json,md}\"","clean":"rm -rf dist"},"dependencies":{"@archlast/sdk-core":"^0.1.1","@tanstack/react-query":"^5.62.11","better-auth":"^1.4.10"},"devDependencies":{"next":">=15.0.0","react":"^18.0.0 || ^19.0.0","react-dom":"^18.0.0 || ^19.0.0","typescript":"^5.0.0","tsup":"^8.5.1","prettier":"^3.4.2","@types/react":"^19","@types/react-dom":"^19"},"peerDependencies":{"next":">=15.0.0","react":"^18.0.0 || ^19.0.0","react-dom":"^18.0.0 || ^19.0.0"},"_id":"@archlast/sdk-next@0.1.1","gitHead":"5c702f9d66c02436cf156c2bd7791beb6764360d","bugs":{"url":"https://github.com/algochad/archlast-sync/issues"},"homepage":"https://github.com/algochad/archlast-sync#readme","_nodeVersion":"22.20.0","_npmVersion":"10.9.3","dist":{"integrity":"sha512-pxcSWM4vBNjDhDlY69PBHBzHSDA2Eow0xXVQgoAxuj0HvQNawln1KUbioU+wnNfnsEidxxLNTzZuj9t5yJfruQ==","shasum":"919a30a10f021dd408b1c300c300dc2266b8eccc","tarball":"https://registry.npmjs.org/@archlast/sdk-next/-/sdk-next-0.1.1.tgz","fileCount":20,"unpackedSize":444965,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIAvLA3C2DhX5YsoIgSklRIfAL9n32gKBkMnLNKow+/ziAiEAs6rv9ljbOJdCn96awWMY4A8Fqy4PtsGZcyLuHmDdOrs="}]},"_npmUser":{"name":"algochad","email":"givillamor01@gmail.com"},"directories":{},"maintainers":[{"name":"algochad","email":"givillamor01@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/sdk-next_0.1.1_1769954258929_0.08794087872429412"},"_hasShrinkwrap":false}},"time":{"created":"2026-02-01T13:57:38.878Z","0.1.1":"2026-02-01T13:57:39.106Z","modified":"2026-02-01T13:57:39.289Z"},"maintainers":[{"name":"algochad","email":"givillamor01@gmail.com"}],"description":"Archlast SDK for Next.js with SSR support","homepage":"https://github.com/algochad/archlast-sync#readme","repository":{"type":"git","url":"git+https://github.com/algochad/archlast-sync.git"},"bugs":{"url":"https://github.com/algochad/archlast-sync/issues"},"license":"MIT","readme":"# @archlast/sdk-next\n\nArchlast SDK for Next.js with SSR (Server-Side Rendering) support.\n\n## Installation\n\n```bash\nnpm install @archlast/sdk-next\n```\n\n## Features\n\n- **SSR Session Reading**: Get session data in server components and route handlers\n- **Middleware Helpers**: Cookie-based authentication checks for protected routes\n- **Better-Auth Wrapped**: No need to install `better-auth` directly\n- **App Router Support**: Built for Next.js 15+ App Router\n- **Type-Safe**: Full TypeScript support\n\n## Usage\n\n### Server Components\n\n```tsx\nimport { getServerSession } from \"@archlast/sdk-next\";\n\nexport default async function Profile() {\n  const session = await getServerSession();\n\n  if (!session) {\n    return <div>Please sign in</div>;\n  }\n\n  return <div>Welcome, {session.user.name}!</div>;\n}\n```\n\n### Route Handlers\n\n```ts\nimport { getServerSession } from \"@archlast/sdk-next\";\nimport { NextResponse } from \"next/server\";\n\nexport async function GET() {\n  const session = await getServerSession();\n\n  if (!session) {\n    return NextResponse.json({ error: \"Unauthorized\" }, { status: 401 });\n  }\n\n  return NextResponse.json({ user: session.user });\n}\n```\n\n### Middleware\n\n```ts\n// middleware.ts\nimport { requireAuth } from \"@archlast/sdk-next\";\nimport { NextRequest } from \"next/server\";\n\nexport function middleware(request: NextRequest) {\n  // Protect all routes except /login and /api/auth\n  if (\n    !request.nextUrl.pathname.startsWith(\"/login\") &&\n    !request.nextUrl.pathname.startsWith(\"/api/auth\")\n  ) {\n    const authResult = requireAuth(request, \"/login\");\n    if (authResult) return authResult;\n  }\n\n  return NextResponse.next();\n}\n\nexport const config = {\n  matcher: [\"/((?!api/auth|_next/static|_next/image|favicon.ico).*)\"],\n};\n```\n\n### Client Components\n\n```tsx\n\"use client\";\n\nimport { useAuth } from \"@archlast/sdk-next/react\";\n\nexport default function Profile() {\n  const { session, isLoading } = useAuth();\n\n  if (isLoading) return <div>Loading...</div>;\n  if (!session) return <div>Please sign in</div>;\n\n  return <div>Welcome, {session.user.name}!</div>;\n}\n```\n\n### Using Better-Auth Directly\n\n```tsx\n\"use client\";\n\nimport { authClient } from \"@archlast/sdk-next/auth\";\n\nexport default function LoginForm() {\n  const handleSubmit = async () => {\n    await authClient.signIn.email({\n      email: \"user@example.com\",\n      password: \"password\",\n    });\n  };\n\n  return <button onClick={handleSubmit}>Sign In</button>;\n}\n```\n\n## Environment Variables\n\n```env\n# Optional: Set Better-Auth server URL\n# Defaults to http://localhost:4000/api/auth\nNEXT_PUBLIC_BETTER_AUTH_URL=http://localhost:4000\n\n# Or use Archlast URL\nNEXT_PUBLIC_ARCHLAST_HTTP_URL=http://localhost:4000\n```\n\n## API\n\n### Server Functions\n\n- `getServerSession()` - Get session in server components/route handlers\n- `getCookieHeader()` - Get cookies as string for forwarding\n- `getSessionHeaders()` - Get headers for authenticated requests\n\n### Middleware\n\n- `createMiddlewareClient(request)` - Create middleware client\n- `requireAuth(request, redirectTo?)` - Helper to protect routes\n\n### Auth\n\n- `authClient` - Better-Auth client for sign in/out\n- `useSession()` - Hook for session state\n- `createAuthClient(options)` - Create custom auth client\n\n## Examples\n\n### Protected Server Component\n\n```tsx\nimport { getServerSession } from \"@archlast/sdk-next\";\nimport { redirect } from \"next/navigation\";\n\nexport default async function Dashboard() {\n  const session = await getServerSession();\n\n  if (!session) {\n    redirect(\"/login\");\n  }\n\n  return (\n    <div>\n      <h1>Dashboard</h1>\n      <p>Welcome, {session.user.name}!</p>\n    </div>\n  );\n}\n```\n\n### API Route with Session\n\n```ts\nimport { getServerSession } from \"@archlast/sdk-next\";\nimport { NextResponse } from \"next/server\";\n\nexport async function POST(request: Request) {\n  const session = await getServerSession();\n\n  if (!session?.user) {\n    return NextResponse.json({ error: \"Unauthorized\" }, { status: 401 });\n  }\n\n  // Process request...\n  return NextResponse.json({ success: true });\n}\n```\n\n## License\n\nMIT\n","readmeFilename":"README.md","_rev":"1-abbd26230d5e109e43be6cc7ff268f14"}