Learn how to hook up Kroxt BaaS to a Next.js App Router application.
Run npx create-kroxt-app, select **Next.js**, and input your Project ID and API Key when prompted.
NEXT_PUBLIC_KROXT_PROJECT_ID=YOUR_PROJECT_ID
NEXT_PUBLIC_KROXT_API_KEY=YOUR_PUBLIC_API_KEYimport { Kroxt } from "@kroxt/baas-sdk";
export const baas = new Kroxt({
projectId: process.env.NEXT_PUBLIC_KROXT_PROJECT_ID || "",
apiKey: process.env.NEXT_PUBLIC_KROXT_API_KEY || "",
});
export default baas;Use type-safe document generics (`Document`) to query and modify collection records:
"use client";
import { useEffect, useState } from "react";
import { Document } from "@kroxt/baas-sdk";
import { baas } from "@/lib/kroxt";
type Todo = Document<{
text: string;
completed: boolean;
}>;
export default function Page() {
const [todos, setTodos] = useState<Todo[]>([]);
useEffect(() => {
// Resolve collection schema with types
baas.collection<{ text: string; completed: boolean }>("todos")
.get()
.then((data) => setTodos(data as Todo[]));
}, []);
return (
<div className="p-6">
<h1 className="text-lg font-bold text-white">My Todos</h1>
<ul className="mt-4 space-y-2">
{todos.map((todo) => (
<li key={todo._id} className="p-3 bg-zinc-900 rounded-xl border border-zinc-800 text-xs text-zinc-300">
{todo.data.text} - {todo.data.completed ? "Done" : "Pending"}
</li>
))}
</ul>
</div>
);
}