Skip to main content

Introduction

lerix.notifications is a typed client for the push notifications REST API. A common setup is a Supabase Database Webhook that calls an edge function, which pushes to the users affected by the change.
Sending needs a private key with the send push notifications permission, created in the Project Settings of the project your app uses. It is not the SDK key. Keep it in a function secret, never in client code.

Configure

notifications.projectId defaults to the SDK’s projectId. Set it when your functions report to one project and your mobile app lives in another.

Example: push when an order ships

Create a Database Webhook on UPDATE of orders that calls this function:
supabase/functions/order-status-push/index.ts
externalUserIds are your own user ids, as passed to setUser() in the client SDKs. One send reaches every device the user is signed in on, on every platform. See Users & Identity.

Send

The result has the notificationId. For externalUserIds sends it also has matchedUsers, matchedDevices and unknownUserIds (users with no device yet, which is not an error).

Update, unsend, cancel, deliveries

API errors throw LerixApiException with the backend’s code and status.

Identity verification

When the project requires identity verification, each setUser() call needs an identityHash computed on your server. An edge function is a good place for it:
It is the lowercase hex HMAC-SHA256 of the user id, the same value the NestJS, Python and .NET SDKs compute. It is async here because Web Crypto is.