1 Install nstack.ai

Every package should use the same version.

$ npm install @nstack/client @nstack/react @nstack/react-ui

2 Set up authentication

Create an authentication API route with prepareSession, passing a unique user ID. Each user has their own set of private chats, and this allows nstack.ai to identify who is connecting.

app/api/liveblocks-auth/route.ts
import { NStack } from "@nstack/node";
import { NextRequest } from "next/server";

const nstack = new NStack({
  secret: process.env.NSTACK_SECRET_KEY!,
});

export async function POST (req: NextRequest) {
  // Get the current user from your database
  const user = {
    id: "user-1",
    // ...
  };
  // ...
}
AI Assistant