Skip to content

fix: [SDK-4341] populate push token from raw subscription for local-id models#1455

Closed
sherwinski wants to merge 3 commits intomainfrom
fix/SDK-4341-safari-empty-push-token
Closed

fix: [SDK-4341] populate push token from raw subscription for local-id models#1455
sherwinski wants to merge 3 commits intomainfrom
fix/SDK-4341-safari-empty-push-token

Conversation

@sherwinski
Copy link
Copy Markdown
Contributor

@sherwinski sherwinski commented Apr 28, 2026

Description

1 Line Summary

Fix subscriptions created with no push token when login() is called before optIn().

Details

When login() creates a placeholder SubscriptionModel with a local- id and empty token: '', the subsequent optIn() flow obtains the real push token via rawPushSubscription. However, Branch 2 of updatePushSubscriptionModelWithRawSubscription was calling createSubscribedUser(pushModel) with the stale empty-token model, discarding the rawPushSubscription entirely:

// Branch 2 (before fix): rawPushSubscription is never used
if (IDManager._isLocalId(pushModel.id)) {
  return createSubscribedUser(pushModel); // pushModel.token is '' from login() placeholder
}

The fix extracts the model-update logic into updateModelFromRawSubscription() and calls it before createSubscribedUser() in the local-id branch, ensuring the token, web_auth, and web_p256 fields are populated from the actual push subscription data.

Systems Affected

  • WebSDK
  • Backend
  • Dashboard

Validation

Tests

Info

  • Added a new unit test should populate token from rawPushSubscription when model has local id and empty token (SDK-4341) that reproduces the exact bug conditions: a model with a local- id and token: '' (the realistic state produced by login()). This test failed before the fix and now passes.
  • Updated the existing should create user if push subscription model has a local id test to expect the web_auth and web_p256 fields that are now correctly populated from the raw subscription.

Checklist

  • All the automated tests pass or I explained why that is not possible
  • I have personally tested this on my machine or explained why that is not possible
  • I have included test coverage for these changes or explained why they are not needed

Programming Checklist
Interfaces:

  • Don't use default export
  • New interfaces are in model files

Functions:

  • Don't use default export
  • All function signatures have return types
  • Helpers should not access any data but rather be given the data to operate on.

Typescript:

  • No Typescript warnings
  • Avoid silencing null/undefined warnings with the exclamation point

Other:

  • Iteration: refrain from using elem of array syntax. Prefer forEach or use map
  • Avoid using global OneSignal accessor for context if possible. Instead, we can pass it to function/constructor so that we don't call OneSignal.context

Screenshots

Info

N/A — internal logic fix with no UI changes.

Checklist

  • I have included screenshots/recordings of the intended results or explained why they are not needed

Related Tickets


…d models

When login() creates a placeholder SubscriptionModel with a local id and
empty token, the subsequent optIn() flow obtains the real push token via
rawPushSubscription but Branch 2 of updatePushSubscriptionModelWithRawSubscription
discarded it — sending the empty-token model to the server as-is.

Extract the model-update logic into updateModelFromRawSubscription() and
call it before createSubscribedUser() in the local-id branch so the token,
web_auth, and web_p256 fields are populated from the actual push subscription.
…ption

Adds a test that reproduces the exact bug conditions: a placeholder model
with a local id and token: '' (the state login() creates). Also updates
the existing local-id test to expect web_auth and web_p256 fields.
@sherwinski sherwinski force-pushed the fix/SDK-4341-safari-empty-push-token branch from 795644c to 6c137d8 Compare April 28, 2026 21:57
@sherwinski sherwinski requested a review from fadi-george April 28, 2026 22:02
@sherwinski sherwinski changed the title fix: [SDK-4341] populate push token from raw subscription for local-id models fix: populate push token from raw subscription for local-id models Apr 28, 2026
@fadi-george
Copy link
Copy Markdown
Contributor

fadi-george commented Apr 29, 2026

whats the original issue? is it just this "login() is called before optIn()."?

@sherwinski
Copy link
Copy Markdown
Contributor Author

whats the original issue? is it just this "login() is called before optIn()."?

Yes, specifically login() has to fail/retry or there has to be some latency in the response. login() creates a placeholder model with token: '', and if Branch 2 of updatePushSubscriptionModelWithRawSubscription is reached (model still has a local- id), the actual token from the push subscription is discarded.

It's difficult to reproduce manually which is why I'm basing the fix off of unit tests.

@fadi-george
Copy link
Copy Markdown
Contributor

Include ticket id in pr title.

@sherwinski sherwinski changed the title fix: populate push token from raw subscription for local-id models fix: [SDK-4341] populate push token from raw subscription for local-id models May 1, 2026
@fadi-george
Copy link
Copy Markdown
Contributor

We need more details from the customer.

@sherwinski
Copy link
Copy Markdown
Contributor Author

Closing for now until we hear back

@sherwinski sherwinski closed this May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants