JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 16
  • Score
    100M100P100Q94525F
  • License MIT

Next.js integration for InAI Auth SDK

Package Exports

  • @inai-dev/nextjs
  • @inai-dev/nextjs/middleware
  • @inai-dev/nextjs/server

Readme

@inai-dev/nextjs

Full Next.js integration for InAI Auth. Includes middleware, server-side helpers, API route handlers, and re-exports all React hooks/components.

Installation

npm install @inai-dev/nextjs

Setup

1. Environment Variables

NEXT_PUBLIC_INAI_PUBLISHABLE_KEY=pk_live_...
INAI_SECRET_KEY=sk_live_...

2. Middleware

// middleware.ts
import { authMiddleware } from "@inai-dev/nextjs/middleware";

export default authMiddleware({
  publishableKey: process.env.NEXT_PUBLIC_INAI_PUBLISHABLE_KEY!,
  publicRoutes: ["/", "/about", "/sign-in"],
});

export const config = { matcher: ["/((?!_next|static|favicon.ico).*)"] };

3. Provider

// app/layout.tsx
import { InAIProvider } from "@inai-dev/nextjs";

export default function RootLayout({ children }) {
  return <InAIProvider>{children}</InAIProvider>;
}

4. Server-Side Auth

// app/dashboard/page.tsx
import { auth } from "@inai-dev/nextjs/server";

export default async function Dashboard() {
  const session = await auth();
  if (!session) redirect("/sign-in");
  return <p>Welcome {session.user.email}</p>;
}

5. API Route Handlers

// app/api/auth/[...inai]/route.ts
import { handleAuthRoutes } from "@inai-dev/nextjs";
export const { GET, POST } = handleAuthRoutes();

Exports

  • @inai-dev/nextjs — Provider, React hooks, API route handler
  • @inai-dev/nextjs/serverauth(), currentUser(), server-side helpers
  • @inai-dev/nextjs/middlewareauthMiddleware()

Documentation

License

MIT