question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

handleCodeFlow is executed twice

See original GitHub issue

Describe the bug It seems handleCodeFlow is executed twice: one succeeds because it can access the PKCE code, and the second one fails as it does not have a code_verifier attribute. The second one kicks off a cascade of errors stemming from either invalid_request or invalid_grant. Sometimes this leads to authentication failure, even though the response from the hosted UI was successful.

Authentication fails sporadically even though my hosted UI flow was successful, and even though my code could be redeemed successfully.

To Reproduce Running on: “aws-amplify”: “^1.1.29”, “aws-amplify-react-native”: “^2.1.9”,

Steps to reproduce the behavior:

  1. use Expo 33 (ejected) with RN 59.8
  2. use hosted UI w/Cognito as the provider
  3. configure oauth with the expo urlOpener
  4. register for hub events in a login component
  5. sign in and observe two “Calling token endpoint” debug messages
  6. one will have a code_verifier attribute and one won’t
  7. sporadic authentication failure (keep retrying and it’ll happen eventually)

The subsequent request that fails will bounce between invalid_grant and invalid_request. It alternates, and I can’t seem to spot a pattern that explains why auth fails when it does vs. when it passes.

Expected behavior I would expect only a single login event, and the handleCodeFlow code to only run once so that there’s no conflict between what can consume the PKCE value.

Screenshots If applicable, add screenshots to help explain your problem.

Smartphone (please complete the following information):

  • Device: iPhone XR (simulator)
  • OS: iOS 12

Additional context Note: this implements a change to _handleCodeFlow to address the bug in #3247 – the only change that’s made is to replace the body: body part of the fetch. The issue is as described in this comment, too.

Seems like it may be related to #3183

Sample code Include additional sample code or a sample repository to help us reproduce the issue. (Be sure to remove any sensitive data)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:14

github_iconTop GitHub Comments

5reactions
alexofobcommented, Dec 17, 2019

Hi there, I am using amplify on the web with react and I am experiencing this issue. So this issue is not only with react native. The amplify team needs to fix this.

3reactions
rkgrepcommented, Dec 24, 2019

@alexofob I had the same issue with event triggered twice on web, because I had .configure executed twice in the code - so it assigned urlListener event twice. In my case it was Amplify.configure({ Auth: ... }) and Auth.configure({ ... }) in another part.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is this Javascript code executed twice? - Stack Overflow
Check if you are adding the click handler twice, maybe that is what is causing that behavior. In that case remove one of...
Read more >
JS code runs twice, on client and server? (not sure) : r/nextjs
I'm trying to update my global state from a nested component using useContext, and I wanted the state to change onClick, but when...
Read more >
Accuracy issue on ResNet50 - inference - GitAnswer
When running on CPU, it matches the one specified in the document, 76.456%. However, I got 76.460% when ... handleCodeFlow is executed twice...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found