Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

okta-react: SecureRoute updates state during an existing state transition #138

Closed
mschaeffner opened this issue Mar 7, 2018 · 4 comments

Comments

@mschaeffner
Copy link

This is caused by using setState inside render and results in following error in the Javascript console:

Warning: setState(...): Cannot update during an existing state transition (such as within render or another component's constructor). Render methods should be a pure function of props and state; constructor side-effects are an anti-pattern, but can be moved to componentWillMount.

The problem is the call this.props.auth.login() in the render function of SecureRoute.js.

This error can be reproduced by running the test app in okta-oidc-js/packages/okta-react/test/e2e/harness/.

  • start the test app with npm start
  • go to http://localhost:3000/
  • make sure you are not logged in
  • click the link Protected
  • see the error in Javascript console

See also discussion in Okta dev forum:
https://devforum.okta.com/t/react-integration-example/800

@robertjd
Copy link
Contributor

This change is now available in version 1.0.2 on npm. Thanks again @mschaeffner !

@zg-trinac
Copy link

I'm running into this now, seems like the Okta docs is still recommending the same or a similar action for the widget onAuthRequired?

[email protected]
@okta/[email protected]
@okta/[email protected]

@swiftone
Copy link
Contributor

@zg-trinac: This exact github issue is a few major versions behind the code you are running, and you're probably seeing a slightly different error.

Could you open a new issue with details about the error you are seeing?

When you do so, could you please expand your question a bit, as I'm not clear which recommendation you are asking about.

@zg-trinac
Copy link

My bad, filed it here: #873

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants