Skip to content

Web SDK Refactor: Login Updates #1299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 27, 2025
Merged

Web SDK Refactor: Login Updates #1299

merged 5 commits into from
May 27, 2025

Conversation

fadi-george
Copy link
Contributor

@fadi-george fadi-george commented May 19, 2025

Description

1 Line Summary

Continuation of the Web SDK Refactor project.

Details

  • Updates test setup to mock op repo timer constants
  • Removes login tests and moves them to OneSignal.test
  • Updates RefreshUserOperation to copy any properties from response
  • In UserDirector for initializeUser, waits for delay since it will error if OneSignal.init and OneSignal.login enqueue ops in the same bucket
  • Updates OneSignal login to mimic Android SDK behavior somewhat via enqueuing a login operation. If an external id is not present, it will set an alias. If there is an external id, it will create a new user.

Systems Affected

  • WebSDK
  • Backend
  • Dashboard

Validation

Tests

Info

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

Checklist

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

Related Tickets



This change is Reviewable


@fadi-george fadi-george changed the title Login Updates Web SDK Refactor: Login Updates May 19, 2025
@fadi-george fadi-george requested review from jkasten2 and sherwinski and removed request for jkasten2 May 19, 2025 19:34
tags?: Record<string, string>;
language?: string;
timezoneId?: string;
timezone_id?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the reason for renaming this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We store property as timezone_id in properties model so in PropertyOperationHelper, there would be a mistake on this line if (allowedKeys.includes(propertyKey)) { since timezoneId is different from timezone_id. So when the request is made to updateUser with new properties. The change to timezone will be ignored since properties object will have an undefined timezoneid value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not following, why wouldn't we want to update the timezone?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you were asking about renaming it

@@ -49,10 +57,13 @@ export default class UserDirector {
...rest,
}),
);

// in case init and login are in the same bucket
await delay(OP_REPO_EXECUTION_INTERVAL * 2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand what the intention is here

Copy link
Contributor Author

@fadi-george fadi-george May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ill update the comment to be this:
// in case OneSignal.init and OneSignal.login are both called in a short time period
// we need this create operation to finish before attempting to execute the login (with external id) operation
// otherwise the login operation executor will error since there will be two login operations

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I can't think of a better way to guard against this (maybe by adding some kind of isExecuting flag) but generally I don't think we should rely on waits protecting us against race conditions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ill look into reset identity model and properties model onesignal id for login, logout, and init

Comment on lines +21 to +23
// OneSignalDeferred.push(async function (OneSignal) {
// await OneSignal.login('new-web-sdk');
// });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uncomment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can just let whoever uncomment it if they need to.

appId,
currentOneSignalId,
externalId,
!currentExternalId ? currentOneSignalId : undefined,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this save the externalId as currentOneSignalId locally? Or is this actually how it's saved on the backend when a user is created?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Android SDK does some other things like reset the onesignal & external ids. I feel these dont need to be done since the login operation executor will update the values as along the identity model values if theres matching ids.
For this login operation, if theres no external id previously then it will call a set alias operation.
If there is a previous external id, it will create a new user.

@fadi-george fadi-george merged commit 6f76326 into web-refractor May 27, 2025
2 checks passed
@fadi-george fadi-george deleted the fg/login branch May 27, 2025 17:51
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.

2 participants