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

Security onAuthRequired for custom widget causes React warning: Cannot update during an existing state transition... #873

Open
2 of 8 tasks
zg-trinac opened this issue Aug 21, 2020 · 0 comments

Comments

@zg-trinac
Copy link

zg-trinac commented Aug 21, 2020

I'm submitting this issue for the package(s):

  • jwt-verifier
  • okta-angular
  • oidc-middleware
  • okta-react
  • okta-react-native

I'm submitting a:

  • Bug report
  • Feature request
  • Other (Describe below)

Current behavior

Following the steps in the React Okta widget guide to redirect to a new login page causes a React error / warning, which seems to imply it's not following React or react-router-dom best practices.

This code example from that guide:

export default withRouter(class AppWithRouterAccess extends Component {
  / * other code... */
  onAuthRequired() {
    this.props.history.push('/login')
  }
}

Going to a Secure route causes this error in the console on redirect:

Warning: Cannot update during an existing state transition (such as within `render`). Render methods should be a pure function of props and state.
    in RequireAuth (created by WrappedComponent)
    in WrappedComponent (created by Context.Consumer)
    in Route (created by SecureRoute)
    in SecureRoute (at AppRouter/index.js:58)
    in Switch (at AppRouter/index.js:34)
    in Security (at AppRouter/index.js:26)
    in AppRouter (created by Context.Consumer)
    in withRouter(AppRouter) (at App.js:13)
    in Router (created by BrowserRouter)
    in BrowserRouter (at App.js:12)
    in ThemeProvider (at App.js:11)
    in App (at src/index.js:5)

Expected behavior

Works as it does currently (redirects to login screen when going to Secure route in the browser) but no error.

Minimal reproduction of the problem with instructions

  1. Check out samples-js-react/custom-login and updated versions to match my project (see Environment)
  2. Go to /messages route and open the console.

Extra information about the use case/user story you are trying to implement

I was testing the Okta login widget with the idea of dynamically swapping Okta clients, but scrapped that idea.

Environment

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

1 participant