Skip to content
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

Auto switch account if user only has 1 device connected when login #5281

Conversation

cmonfortep
Copy link
Contributor

@cmonfortep cmonfortep commented Nov 15, 2024

Task/Issue URL: https://app.asana.com/0/1203822806345703/1208755822305613/f

Description

Introduces logic to switch the user account if sync has only 1 device connected.
When multiple devices connected, we still ask the user.

Steps to test this PR

Feature 1

  • Fresh install
  • Go to Feature flags and enable FF seamlessAccountSwitching
  • Create a sync account
  • Save or copy the recovery code
  • logout
  • Create a new sync account
  • Go to "Sync With Another Device", and read or paste the recovery code
  • Ensure user is automatically switched to the other account

Feature 1

  • Fresh install
  • Go to Feature flags and enable FF seamlessAccountSwitching
  • Create a sync account
  • Save or copy the recovery code
  • logout
  • Join this account -> https://app.asana.com/0/1203822806345703/1208795798275452/f
  • you are connected to an account with more devices
  • Go to "Sync With Another Device", and read or paste the recovery code from the first account you created
  • Ensure you are asked to confirm switching accounts

UI changes

Before After
!(Upload before screenshot) (Upload after screenshot)

@cmonfortep
Copy link
Contributor Author

cmonfortep commented Nov 15, 2024

@cmonfortep cmonfortep marked this pull request as ready for review November 19, 2024 10:24
@cmonfortep cmonfortep force-pushed the feature/cristian/sync/offer_join_account_as_option branch from 95ba72c to 3941975 Compare November 19, 2024 10:38
@cmonfortep cmonfortep force-pushed the feature/cristian/sync/auto_switch_single_device_account branch from 5e3ae88 to b60c4a3 Compare November 19, 2024 10:38
@cmonfortep cmonfortep force-pushed the feature/cristian/sync/offer_join_account_as_option branch from 5f14b03 to 7ab217c Compare November 19, 2024 12:45
@cmonfortep cmonfortep force-pushed the feature/cristian/sync/auto_switch_single_device_account branch 2 times, most recently from 2f94d43 to 0d49333 Compare November 19, 2024 12:49
@cmonfortep cmonfortep force-pushed the feature/cristian/sync/offer_join_account_as_option branch from 7ab217c to 29721ff Compare November 19, 2024 13:40
@cmonfortep cmonfortep force-pushed the feature/cristian/sync/auto_switch_single_device_account branch from 0d49333 to 4965dc7 Compare November 19, 2024 13:41
@cmonfortep cmonfortep requested a review from CDRussell November 19, 2024 17:31
@CDRussell CDRussell self-assigned this Nov 20, 2024
Comment on lines +37 to +47
<issue
id="DenyListedApi"
message="If you find yourself using this API in production, you&apos;re doing something wrong!!"
errorLine1=" this.seamlessAccountSwitching().setRawStoredState(State(true))"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/test/java/com/duckduckgo/sync/impl/AppSyncAccountRepositoryTest.kt"
line="100"
column="9"/>
</issue>

Copy link
Member

Choose a reason for hiding this comment

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

Nit: For tests, think we should just suppress the lint warning instead of using the baseline (to avoid lint errors resurfacing in the future when the file is changed).

@@ -288,6 +300,7 @@ class AppSyncAccountRepository @Inject constructor(

return when (val result = syncApi.getDevices(token)) {
is Error -> {
connectedDevicesCached.clear()
Copy link
Member

Choose a reason for hiding this comment

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

why is this added? if there is a blip in the network and getDevices call fails, do we want to clear the cached list?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a convenient, quick solution, for us to have the latest response from get device in memory, so we can use it in the prompt logic. It's fine to clear on error, and only update/store on success.

@cmonfortep cmonfortep force-pushed the feature/cristian/sync/offer_join_account_as_option branch from 29721ff to 94f20f0 Compare November 21, 2024 13:55
@cmonfortep cmonfortep force-pushed the feature/cristian/sync/auto_switch_single_device_account branch from 4965dc7 to 65c9705 Compare November 21, 2024 13:55
@cmonfortep cmonfortep force-pushed the feature/cristian/sync/offer_join_account_as_option branch from 94f20f0 to 043a10a Compare November 21, 2024 20:14
@cmonfortep cmonfortep force-pushed the feature/cristian/sync/auto_switch_single_device_account branch from 65c9705 to a88564f Compare November 21, 2024 20:14
Task/Issue URL:
https://app.asana.com/0/72649045549333/1208755822305614/f

### Description
Adds metrics around dialog engagement and errors.

### Steps to test this PR

_single device flow metrics_
- [x] Fresh install
- [x] Go to Feature flags and enable FF seamlessAccountSwitching
- [x] Create a sync account
- [x] Save or copy the recovery code
- [x] logout
- [x] Create a new sync account
- [x] Go to "Sync With Another Device", and read or paste the recovery
code
- [x] Ensure user is automatically switched to the other account
- [x] Ensure following pixels where triggered:
sync_user_switched_account

_multiple devices flow metrics_
- [x] Fresh install
- [x] Go to Feature flags and enable FF seamlessAccountSwitching
- [x] Create a sync account
- [x] Save or copy the recovery code
- [x] logout
- [x] Join this account ->
https://app.asana.com/0/1203822806345703/1208795798275452/f
- [x] you are connected to an account with more devices
- [x] Go to "Sync With Another Device", and read or paste the recovery
code from the first account you created
- [x] Ensure you are asked to confirm switching accounts
- [x] Ensure pixel is triggered: sync_ask_user_to_switch_account
- [ ] Click on Cancel and ensure pixel is triggered:
sync_user_cancelled_switching_account
- [x] Repeat the connection but now click "Switch"
- [x] Ensure pixel is triggered: sync_user_accepted_switching_account
- [x] If Switch is successful, ensure pixel is triggered:
sync_user_switched_account

_error metrics_
- [x] Fresh install
- [x] Go to Feature flags and enable FF seamlessAccountSwitching
- [x] Create a sync account
- [x] Save or copy the recovery code
- [x] INSTEAD OF LOGOUT, DELETE THE ACCOUNT (scroll to the bottom part
of the screen)
- [x] Create a new sync account
- [x] Go to "Sync With Another Device", and read or paste the recovery
code
- [x] This will fail since the account doesn't exist (you will see
another error that says invalid_login_credentials, it's expected)
- [x] Ensure following pixels where triggered:
sync_user_switched_logout_error
- [x] Going back you will be in logout state


### UI changes
| Before  | After |
| ------ | ----- |
!(Upload before screenshot)|(Upload after screenshot)|
@cmonfortep cmonfortep merged commit 581a091 into feature/cristian/sync/offer_join_account_as_option Nov 22, 2024
4 of 5 checks passed
@cmonfortep cmonfortep deleted the feature/cristian/sync/auto_switch_single_device_account branch November 22, 2024 16:43
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