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(singleton): allow oauth listener to be called with the latest config #13642

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

israx
Copy link
Member

@israx israx commented Jul 24, 2024

Description of changes

Amplify.configure will call oAuthListener and it will pass the Auth config. This oAuthListener is responsable for completing an OAuth flow. However when Amplify.configure is called more than 1 time, the oAuthListener will be called only with the first Auth config.

This fix makes sure the oAuthListener is called only and only if a valid OAuth config and oAuthListener are already defined. And ensures the oAuthListener is called with the latest config of Amplify.

  • Before
    Amplify.configure with config1 -> Amplify.configure with config2 -> call oAuthListener with config1

  • After
    Amplify.configure with config1 -> Amplify.configure with config2 -> call oAuthListener with config2

Issue #, if available

#12849

Description of how you validated changes

  • smoke testing
  • unit tests

Checklist

  • PR description included
  • yarn test passes
  • Unit Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)

Checklist for repo maintainers

  • Verify E2E tests for existing workflows are working as expected or add E2E tests for newly added workflows
  • New source file paths included in this PR have been added to CODEOWNERS, if appropriate

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

AllanZhengYP
AllanZhengYP previously approved these changes Jul 25, 2024
Comment on lines +111 to +112
// The setTimeout will only be called as long as an oAuthLister and oauth config
// are defined. The code executed by the time out will be only fired once.
Copy link
Member

Choose a reason for hiding this comment

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

This sounds like it only works with certain preconditions, e.g. assuming Amplify.configure() gets called back to back. While this trick seemed to be working, I'm hesitant to make this a solution...

With Amplify Gen2, amplify_outputs.json can be overridden from the backend.ts (reference). With Amplify Gen1, should be able to change the url in amplifyconfiguration.json as well, would be these be legit workarounds to solve what the PR is trying to solve?

Copy link
Member

Choose a reason for hiding this comment

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

I have to echo this sentiment. When I looked at this PR this was my initial concern as well. Code after the configure call that may have previously executed after the this.oAuthListener call was made may now execute after the call due to it being pulled out of the current execution cycle. While I'm not certain that is practically concerning, it feels quite risky.

Comment on lines +111 to +112
// The setTimeout will only be called as long as an oAuthLister and oauth config
// are defined. The code executed by the time out will be only fired once.
Copy link
Member

Choose a reason for hiding this comment

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

I have to echo this sentiment. When I looked at this PR this was my initial concern as well. Code after the configure call that may have previously executed after the this.oAuthListener call was made may now execute after the call due to it being pulled out of the current execution cycle. While I'm not certain that is practically concerning, it feels quite risky.

Comment on lines +104 to +106
amplify: AmplifyClass,
config: AuthConfig['Cognito'],
oAuthListener: OAuthListener,
Copy link
Member

Choose a reason for hiding this comment

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

Making this pure would make sense if it were removed completely from the class, but since it is a private member of the class, this seems confusing. For example, it's not really clear to me why oAuthListener is passed separately from this. The clearListenerTimeout is then also tacked onto the instance but it's obfuscated here.

@israx israx marked this pull request as draft July 31, 2024 17:50
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.

4 participants