TsgcWSAPIServer_WebPush › Events › OnWebPushSubscription
Fires when a browser POSTs to the Subscription endpoint after calling PushManager.subscribe(); receive the endpoint, p256dh key and auth secret to persist server-side.
property OnWebPushSubscription: TsgcWSWebPushSubscription;
// TsgcWSWebPushSubscription = procedure(Sender: TObject; aSubscription: TsgcHTTP_API_WebPush_PushSubscription; var ResponseCode: Integer) of object
—
The component already stores the new subscription in the internal Subscriptions list so it becomes reachable by BroadcastNotification. Use the event to persist the incoming subscription to your own database and/or apply server-side validation (authentication, rate limiting, duplicate detection). Set ResponseCode to the HTTP status returned to the browser — return 200/201 on success or a 4xx to reject (for instance 401 if the user is not authorised).
procedure TForm1.sgcWSAPIServer_WebPush1WebPushSubscription(Sender: TObject;
aSubscription: TsgcHTTP_API_WebPush_PushSubscription; var ResponseCode: Integer);
begin
SaveSubscriptionToDB(aSubscription.Endpoint,
aSubscription.PublicKey,
aSubscription.AuthSecret);
ResponseCode := 201;
end;