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

Fix regressions found in the login with OAuth flow #1976

Merged
merged 4 commits into from Mar 14, 2024

Conversation

amy-at-kickstarter
Copy link
Contributor

@amy-at-kickstarter amy-at-kickstarter commented Mar 13, 2024

📲 What

  1. Make the old login, old sign up, and new OAuth "signup or login" buttons reactive.
  2. Make the default value of the featureLoginWithOAuthEnabled true.

🤔 Why

  1. One copy of our login screen is created as a root view of the app - in the Profile tab in the tab bar. This copy of the screen was always getting the first (ie cached or default value) of featureLoginWithOAuthEnabled(). This means it was never updating, even after new values of the OAuth feature flag loaded. Fixing this bug ensures we can correctly use the feature flag for OAuth, in case we need to ramp down.
  2. If the remote config hasn't loaded yet, we want to show the new flow, not the old flow.

@@ -37,6 +37,10 @@ public final class LoginToutViewController: UIViewController, MFMailComposeViewC
|> \.translatesAutoresizingMaskIntoConstraints .~ false
}()

private lazy var loginOrSignUpWithOAuthButton = { UIButton(type: .custom)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most of this boiler-plate code is splitting out the "Sign up or Log in" button from the "Log In" button, where it was stuffed earlier.

} else {
self.navigationController?.pushViewController(LoginViewController.instantiate(), animated: true)
self.navigationItem.backBarButtonItem = UIBarButtonItem.back(nil, selector: nil)
self.navigationController?.pushViewController(LoginViewController.instantiate(), animated: true)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is now only called by the traditional login button.

}

fileprivate func pushOAuthFlow() {
guard featureLoginWithOAuthEnabled(), let session = createAuthorizationSession() else {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is only called by the new login button.

This way, config flag changes that occur shortly after launch will update the UI appropriately.
@amy-at-kickstarter amy-at-kickstarter force-pushed the feat/adyer/reactive-login-logout-buttons branch from 6c2d6f7 to ad0b58a Compare March 13, 2024 19:23
@amy-at-kickstarter amy-at-kickstarter changed the title Make the display of login/logout/oauth buttons reactive Fix regressions found in the login with OAuth flow Mar 13, 2024
@@ -298,6 +305,10 @@ public final class LoginToutViewController: UIViewController, MFMailComposeViewC
self.contextLabel.rac.text = self.viewModel.outputs.logInContextText
self.bringCreativeProjectsToLifeLabel.rac.hidden = self.viewModel.outputs.headlineLabelHidden

self.loginButton.rac.hidden = self.viewModel.outputs.showLoginWithOAuth
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Either show the new, combined button, or the two old buttons.

let valueFromRemoteConfig = AppEnvironment.current.remoteConfigClient?
.isFeatureEnabled(featureKey: feature)

return valueFromDefaults ?? valueFromRemoteConfig ?? defaultValue
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Slight refactoring to support new default values, and to make this easier to read and debug.

@@ -117,6 +121,43 @@ final class LoginToutViewModelTests: TestCase {
)
}

func testStartSignupOrLoginWithOAuth() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some simple/boilerplate tests, just for sanity.

@amy-at-kickstarter amy-at-kickstarter self-assigned this Mar 13, 2024
@amy-at-kickstarter amy-at-kickstarter marked this pull request as ready for review March 13, 2024 20:36
Copy link
Contributor

@ifosli ifosli left a comment

Choose a reason for hiding this comment

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

Looks good! I just have one minor concern in the remote config code

(AppEnvironment.current.remoteConfigClient?
.isFeatureEnabled(featureKey: feature) ?? false)
let valueFromRemoteConfig = AppEnvironment.current.remoteConfigClient?
.isFeatureEnabled(featureKey: feature)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Unlike before, valueFromRemoteConfig will now be calculated each time. I wouldn't expect that to be a problem (it's probably cached in the remote config client and thus not an expensive operation) but just in case it is actually expensive or always does a network call or something, I think we should stick with early returns. Ex use if let blocks with returns instead of just having one return statement at the end.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, good point - will fix then merge.

@amy-at-kickstarter amy-at-kickstarter merged commit 4566798 into main Mar 14, 2024
5 checks passed
@amy-at-kickstarter amy-at-kickstarter deleted the feat/adyer/reactive-login-logout-buttons branch March 14, 2024 00:21
amy-at-kickstarter added a commit that referenced this pull request Mar 14, 2024
* Make the display of login/logout/oauth buttons reactive.

This way, config flag changes that occur shortly after launch will update the UI appropriately.

* Add tests for OAuth login button in LoginToutViewModelTests

* Make featureLoginWithOAuthEnabled default to true, if no remote or local config is set

* Change per review #1976
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.

None yet

2 participants