puter.notifications.registerDevice()

Websites Puter Apps Node.js Workers

This is for Puter's own web and mobile apps, which decide where pushes go. It needs a signed-in Puter session; an app's token is refused with forbidden. Apps send notifications with notify() and never need it.

Registers a device to receive the user's push notifications, or refreshes it if its token is already registered. A user can have up to 20 devices; registering another removes the one seen least recently.

Syntax

puter.notifications.registerDevice({ platform, token, label })

Parameters

registration (Object) (required)

  • platform (String) (required): 'web', 'ios' or 'android'.
  • token (String) (required): The push token the platform issued for this device.
  • label (String): A name the user will recognize, such as Pixel 8. Up to 64 characters.

Return value

A Promise that resolves to the device:

  • uid (String)
  • platform (String)
  • label (String | null)
  • userAgent (String | null)
  • createdAt (Number): Unix seconds.
  • lastSeenAt (Number): Unix seconds.
  • current (Boolean): Registered from this session.

The push token itself is never returned.

It rejects with an error carrying message and code:

code Meaning
bad_request platform, token or label isn't valid.
forbidden Not called from a signed-in Puter session.
push_device_conflict The token is registered to another account.
push_disabled This server doesn't send push notifications.
push_unavailable This deployment has no push notification service, as on most self-hosted servers.