Illustration of how to send push notification to specific user devices, a server sending one secure alert to a phone and a laptop Illustration of how to send push notification to specific user devices, a server sending one secure alert to a phone and a laptop

How Do You Send a Web Push Notification to One Specific User?

Send web push to one user: store each subscription with the user ID, send to all their devices, clean up 410s and handle logout.

To send a web push notification to one specific user, save each push subscription on your server together with that user’s account ID when they subscribe while logged in. To notify them, look up every subscription linked to their ID and send the message to each endpoint. One person can have several subscriptions, one per browser and device.

This question usually comes up right after a working “send to everyone” flow. Broadcasts are easy, because you loop over every subscription. Targeting one person is different: the browser gives you a subscription, not an identity, so the link between the two is yours to build. Once you see it that way, the design is simple.

Key facts at a glance:

  • A subscription is not a user: a `PushSubscription` contains an endpoint URL and keys, with no name, email or account ID.
  • The link is your job: store `user_id` next to each subscription in your database.
  • One user, many rows: each browser on each device is a separate subscription, per Google’s web.dev guide.
  • Clean up: delete rows when the push service returns 404 or 410, and on logout if alerts are account-private.
  • Typical uses: order updates, replies, account alerts and sign-in confirmations.

How does sending web push to a specific user work?

It works by matching your user ID to stored subscriptions. When a logged-in visitor allows notifications, your page calls `pushManager.subscribe()`, gets a `PushSubscription` and posts it to your server. Your server saves it with the ID of the user who’s signed in.

Later, when something happens for that user, your backend runs a simple query: find every subscription where `user_id` matches. Then it sends the same encrypted message to each endpoint through the Web Push protocol. The push service doesn’t know or care who the user is; it just delivers to that browser. For the underlying flow, see how push notifications work and my explainer on web push endpoint URLs.

What do you need to store for each subscription?

You need the subscription itself plus a few fields that make targeting and clean-up possible. Here is a simple table design:

ColumnExampleWhy you need it
———
user_id48213Links the subscription to your account
endpointhttps://fcm.googleapis.com/…Where the push service accepts messages
p256dh and auth keysbase64 stringsNeeded to encrypt the payload
user_agent or device labelChrome on AndroidLets the user see and remove devices
created_at and last_seen2026-12-02Helps you spot stale rows

Make the endpoint unique. If the same browser subscribes again, update the existing row instead of adding a duplicate, or the user gets the same alert twice. The keys matter too, since web push payloads are encrypted for that subscription; my post on web push encryption explains why.

How do you link a subscription to a logged-in user?

You link it in the request that saves the subscription. Your page sends the subscription JSON to an endpoint on your own server, and that endpoint reads the user ID from the session, not from the request body. That way, nobody can attach their browser to someone else’s account.

  1. Check that the visitor is logged in before showing your push prompt.
  2. Call `registration.pushManager.subscribe()` with your VAPID public key.
  3. POST the subscription JSON to your server, with the session cookie or auth token.
  4. On the server, read the user ID from the session and upsert the row by endpoint.
  5. Return success, then show a short “alerts are on” message in your UI.

What about visitors who subscribed before logging in? Store their subscription with no user ID, then attach it when they log in on the same browser. In the page, `pushManager.getSubscription()` returns the current subscription, so you can post it again after login.

How do you send to one user on all their devices?

You send to every subscription that belongs to them. web.dev is clear that a user who subscribes on desktop isn’t subscribed on their phone; they must grant permission in each browser. So “send to user 48213” means “send to all rows for 48213”.

In code, that’s a loop. Here’s the idea in plain JavaScript using the popular web-push library for Node.js, as shown in web.dev’s guide to sending messages with web push libraries:

const subs = await db.subscriptions.findAll({ where: { userId: 48213 } });
for (const s of subs) {
  try {
    await webpush.sendNotification(s.subscription, JSON.stringify(payload), { TTL: 3600 });
  } catch (err) {
    if (err.statusCode === 404 || err.statusCode === 410) await db.subscriptions.remove(s.id);
  }
}

Notice the error handling. A 404 or 410 response means that subscription is gone, so delete the row. My guide to 410 Gone and expired subscriptions covers the codes. If you’d rather not show the same alert on three devices at once, use the notification `tag` option so a newer alert replaces an older one in each browser; see one person on multiple devices.

What should happen when a user logs out?

It depends on how private the alerts are. For general alerts, such as “your favourite author posted”, you can keep the subscription after logout. For private alerts, such as order details or account warnings, stop sending to that browser once the user logs out.

You have two options for private alerts:

  • Unlink: set the row’s user ID to empty on logout, so the browser stays subscribed but gets no personal alerts.
  • Unsubscribe: call `PushSubscription.unsubscribe()` in the page, documented on MDN, and delete the row.

Unlinking is usually better on personal devices, because the reader doesn’t have to grant permission again. Unsubscribing is safer on shared computers. In both cases, keep personal data out of the payload where you can. For example, “Your order has shipped” is safer than including the address.

Which use cases suit user-targeted web push?

User-targeted web push suits events that only matter to one person and need attention soon. Here are the common ones:

Use caseExample messageTip
———
Order and delivery updates“Your order has shipped”Link to the order page, not the homepage
Replies and mentions“Someone replied to your comment”Group several replies into one alert
Account security“New sign-in from Chrome on Windows”Keep it short and factual
Saved search or price alert“A product you watch is back in stock”Respect the user’s chosen frequency
Support tickets“Your ticket has a new reply”Use a short TTL

One caution: don’t treat web push as your only channel for critical security codes. Delivery depends on the browser running and the device being online, as I explain in web push for OTP and 2FA. Back-in-stock alerts have their own guide in back-in-stock web push notifications.

Where LaraPush fits

LaraPush is a self-hosted web push panel with an open REST API for creating and sending notifications and managing subscriber tokens, with no call limits or throttling. Because subscriber tokens are stored on your own server, your app and your push data live in infrastructure you control. Check the LaraPush guide for the exact API endpoints before you design per-user targeting around it. The trade-offs: you run the server, the licence covers one server, and there’s no free plan. Prices start from $499 one-time; see LaraPush pricing. For other tools, see my roundup of push notification services and the push notification API guide.

Frequently asked questions

Can you send a web push notification to one user only?

Yes. Store each push subscription with the user’s account ID when they subscribe while logged in. To notify that user, find every subscription with their ID and send the message to each endpoint. The push service delivers only to those browsers.

Does a push subscription contain the user’s email or ID?

No. A PushSubscription contains a push service endpoint URL and encryption keys only. Your server has to link it to a user, usually by saving the logged-in user’s ID next to the subscription when the browser sends it.

How do you send push notifications to a user on multiple devices?

Each browser on each device creates its own subscription, so save all of them under the same user ID. When you send, loop over every matching subscription. Use the notification tag option if you want newer alerts to replace older ones.

What happens to push subscriptions when a user logs out?

The subscription stays active unless you change it. For private alerts, either remove the user ID from that subscription on logout or call PushSubscription.unsubscribe() in the page and delete the row on your server, especially on shared computers.

How do you handle expired push subscriptions for a user?

When the push service returns a 404 or 410 status for an endpoint, the subscription is no longer valid. Delete that row from your database. The user can subscribe again on their next visit if they still want alerts.

Leave a Reply

Your email address will not be published. Required fields are marked *