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

Log out user account after account deletion success #1395

Merged
merged 16 commits into from
Aug 17, 2021

Conversation

charliescheer
Copy link
Contributor

Fix

Per some discussions with in app account deletion for MacOS, we decided that it would be best to log out a user once the account deletion is complete, instead of simply displaying the onboarding. We did this on macOS to deal with some windowing bugs, which were not apparent on iOS, but could lead to being able to navigate the app after an account was deleted making it seem like the deletion had failed.

By logging the user out the local data is removed and there is no way to navigate the app.

Test

  1. Create an account to delete
  2. delete that account.
  3. open simplenote iOS back up, notice that with in a moment or two the onboarding VC will appear.
  4. send simplenote to the background and open it again
  5. You will see the slide out menu for a short moment (this is in part because of the restoration state and I do not think is avoidable) but it can't be interacted with and the onboarding vc should appear quickly

Review

(Required) Add instructions for reviewers. For example:

Only one developer are required to review these changes, but anyone can perform the review.

Release

These changes do not require release notes.

@charliescheer charliescheer added the enhancement Improve existing functionality. label Aug 11, 2021
@charliescheer charliescheer added this to the 4.43 milestone Aug 11, 2021
@charliescheer charliescheer self-assigned this Aug 11, 2021
Simplenote/SPAppDelegate+Extensions.swift Outdated Show resolved Hide resolved
guard let deletionController = accountDeletionController,
deletionController.hasValidDeletionRequest,
let user = simperium.user,
user.authenticated() else {
Copy link
Contributor

Choose a reason for hiding this comment

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

user.authenticated() will be false because we come here when user token is invalid, which means user is not authenticated.
We don't need this condition here and can safely remove it.

Copy link
Contributor

Choose a reason for hiding this comment

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

After I removed user.authenticated() and tested the account deletion flow, I found another issue.

Calling [self.simperium signOutAndRemoveLocalData:YES completion:^{}]; doesn't do anything because the first line there is checking if user is authenticated. It will return false in our case because the token is not valid and singOut won't do anything because of that. This means that all the data is still stored in the core data and we failed to remove it.

https://github.com/Simperium/simperium-ios/blob/develop/Simperium/Simperium.m#L589

- (void)signOutAndRemoveLocalData:(BOOL)remove completion:(SimperiumSignoutCompletion)completion {
    
    // Don't proceed, if the user isn't logged in
    if (!self.user.authenticated) {
        return;
    }

   ...

The issue here is that simperium checks for self.user.authenticated which can be false, but we will still have the user object and credentials stored in the keychain and on the next app launch Simperium will try to use the token from the keychain. The check is quite misleading.

I suggest that we change if (!self.user.authenticated) to if (!self.user) or even fully remove the line. This should allow us to fully clean the state even if the user is not authenticated.

@jleandroperez WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

Simperium updated here. TY Evgeny!!

+1 yes let's just check if there's a valid deletion request pending.
Plus: we should point to the new Simperium branch (I'll make sure to release a new version once we know it's good!)

Simplenote/SPConstants.h Outdated Show resolved Hide resolved
Copy link
Contributor

@jleandroperez jleandroperez left a comment

Choose a reason for hiding this comment

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

Thank you gentleman 😄

Simplenote/SPAppDelegate+Extensions.swift Outdated Show resolved Hide resolved
Simplenote/SPAppDelegate+Extensions.swift Show resolved Hide resolved
guard let deletionController = accountDeletionController,
deletionController.hasValidDeletionRequest,
let user = simperium.user,
user.authenticated() else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Simperium updated here. TY Evgeny!!

+1 yes let's just check if there's a valid deletion request pending.
Plus: we should point to the new Simperium branch (I'll make sure to release a new version once we know it's good!)

Simplenote/SPAppDelegate.m Outdated Show resolved Hide resolved
@peril-automattic
Copy link

peril-automattic bot commented Aug 12, 2021

You can trigger an installable build for these changes by visiting CircleCI here.

@peril-automattic
Copy link

peril-automattic bot commented Aug 12, 2021

You can trigger optional UI/connected tests for these changes by visiting CircleCI here.

@charliescheer
Copy link
Contributor Author

charliescheer commented Aug 13, 2021

Alright, tested the simperium changes, and that does work. It created a new issue where the onboarding screen was loaded for a moment then it is dismissed, and then it is displayed again. This happens because of simperium.authenticationDidFail schedules an onboarding VC to appear and logout calls dismissAllModals and then also calls authenticateIfNecessary which schedules a new onboarding VC. I removed the call to dismiss all modals to fix the issue.

Also I added a change that fixes #1393 (adding that in so it will auto close when this is merged)

To test these changes with the simperium changes in the SNiOS Pod file comment out
pod 'Simperium', '1.8.0'

and add

pod 'Simperium', :git => 'https://github.com/Simperium/simperium-ios.git', :branch => 'issue/drops-unneeded-logout-check'

@charliescheer charliescheer linked an issue Aug 13, 2021 that may be closed by this pull request
switch simperiumError {
case .invalidToken:
logOutIfAccountDeletionRequested()
break
Copy link
Contributor

Choose a reason for hiding this comment

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

No break needed here

Copy link
Contributor

@eshurakov eshurakov left a comment

Choose a reason for hiding this comment

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

Worked great for me!

@charliescheer
Copy link
Contributor Author

I checked it out as well and it looks good to me @jleandroperez

Copy link
Contributor

@jleandroperez jleandroperez left a comment

Choose a reason for hiding this comment

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

:shipit: sir!

@charliescheer charliescheer merged commit 68b3fdd into develop Aug 17, 2021
@charliescheer charliescheer deleted the issue/account-deletion-logout-on-succes branch August 17, 2021 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improve existing functionality.
Projects
None yet
3 participants