Currently, push subscription tokens are only sent to the backend when the subscription is first created. However, tokens can occasionally update in the background, so it’s important to ensure the server has the latest version.
Here’s how we can keep the backend up-to-date with any token changes:
// app/javascript/push_notifications_controller.js
export default class extends Controller {
connect() {
this.saveSubscription()
}
// …
}
This ensures that the server stays synchronized with the client browser by uploading the token whenever they are available.
P.S. 🎉 I don’t know how it happened, but 2025 is upon us!
If your team could use technical direction or you’re working on an MVP, book a no-obligation call with me. Let’s see how I can help you move further, faster in 2025!