Next.js Discord

Discord Forum

How do I handle database subscriptions?

Unanswered
Chippiparai posted this in #help-forum
Open in Discord
ChippiparaiOP
So, I have the usual overly complicated web application which I'm making an overly complicated todo app with databases and stuff (inspired by Todoist), and I'd want this app to be mostly on the server side, so I decided on PocketBase with Next.js

And now I just realized, that I don't know how to handle realtime database subscriptions. and reading the Next.js docs doesn't seem to help my last 2 brain cells think of an idea of how to implement it.

And I know that I can just betray the server and implement all of this easily on client side (and I'll need to rewrite a lot of code because the server is authenticated as the user, the client only has a 🍪 which stores the authentication token), but is there any way that I can subscribe to a database and do some kind of magic to update the client side?

Additional info: PocketBase is a simple application backend system which handles realtime subscriptions, authentications and has a simple web dashboard, "The Realtime API is implemented via Server-Side Events (SSE)", said the PocketBase Realtime API documentation. And when subscribing to a collection using the official PocketBase JavaScript SDK, the code will be similar to this:
pb.collection('todos').subscribe('*', function (e) {
    console.log(e.action);
    console.log(e.record);
}, { /* other options */ });

0 Replies