Guide
Nuxt/Vue-style CF tutorials, but for Next.js App Router: Route Handler JWT, client useChat, reconnect, and history pagination on Cloudflare Workers + Durable Objects.
// app/api/chat/token/route.ts
export async function POST(req: Request) {
const { userId } = await req.json();
const res = await fetch(`${process.env.FLUXY_WORKER_URL}/auth/token`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-Fluxy-Api-Key": process.env.FLUXY_API_KEY!,
},
body: JSON.stringify({ userId, roles: ["member"], ttlSeconds: 3600 }),
});
return Response.json(await res.json());
}"use client";
import { FluxyChatClient } from "@fluxy-chat/sdk";
import { useChat } from "@fluxy-chat/react";
const client = new FluxyChatClient({
baseUrl: process.env.NEXT_PUBLIC_FLUXYCHAT_CLOUD_URL!,
userId,
token: memberJwt,
});
export function RoomChat({ roomId }: { roomId: string }) {
const { messages, sendMessage, connectionState, loadMore, hasMore } =
useChat({ roomId, client, replay: "connect" });
return (/* render messages + connectionState + loadMore button */);
}Keep Next on Vercel; Worker on Cloudflare. Same pattern as the Nuxt-on-Pages tutorials: different import, same split.
If you landed here from a Next.js realtime chat tutorial and do not want Socket.IO on a VPS, this is the packaged version of that split.
How to Build a Realtime Chat App on Cloudflare Workers (Without Managing a Socket Fleet) →
FluxyChat packages the same stack: RoomDurableObject, D1 history, multi-tenant JWT, reconnect-aware SDK, and operator console. MIT self-host or hosted beta.
Topics: next.js realtime chat cloudflare · nuxt chat durable objects alternative · useChat cloudflare workers · build chat app nextjs vercel
Canonical path: /guides/build-chat-nextjs-fluxychat