Hi — I need help getting realtime working between our Next.js app and a self-hosted NodeBB instance.
We are not embedding the NodeBB UI. NodeBB is the community backend only. Our product UI (posts, forums, chats) lives in Next.js and talks to NodeBB over the Write API / Read API.
What already works
On first login we:
- Create a NodeBB user with the Write API as admin, e.g.
POST /api/v3/userswithAuthorization: Bearerand_uid= admin uid - Store the returned
uidon our user row (Supabase:users.nodebb_id) - For later API calls we impersonate that user with the master token +
_uid= storednodebb_id
REST is fine: topics, posts, votes, bookmarks, categories, chats list/send all work.
What does not work
Realtime does not connect from the Next.js app (browser) to NodeBB Socket.IO.
We need live:
- new posts / replies in the feed
- likes / bookmarks
- chat messages (
chats.receive, unread counts)
Because the browser is a different origin than NodeBB, a direct io(nodebbOrigin) from the Next.js site is what we are trying to get right (CORS, cookies, auth).
How we tried to authenticate the socket
We create a user token server-side:
POST /api/v3/users/:uid/tokens (admin master token + _uid = admin)
Then we planned to connect from the browser with something like:
io(NODEBB_ORIGIN, {
transports: ["websocket", "polling"],
auth: { token }, // or query: { token }
});
Can someone please suggest that how we can do this thing.
You likely need to add a socket.io block to your nodebb config.json and add the next.js app domain in there.
Something like:
save