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

5.x to 6.x, running as a service, reload fails #169

Open
1 of 3 tasks
ahmednkhan24 opened this issue Oct 6, 2021 · 2 comments
Open
1 of 3 tasks

5.x to 6.x, running as a service, reload fails #169

ahmednkhan24 opened this issue Oct 6, 2021 · 2 comments

Comments

@ahmednkhan24
Copy link

ahmednkhan24 commented Oct 6, 2021

I'm submitting a:

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

Current behavior

When a user is logged in, and a SPA is running Okta as a service, a page refresh won't render content to the DOM.

Expected behavior

When a user is logged in, and a SPA is running Okta as a service, a page refresh should render content to the DOM.

Minimal reproduction of the problem with instructions

  • Clone this minimal demo repo
  • Update the values in src/config.js file to an Okta tenant you have access to.
  • Run a yarn && yarn start to install dependencies and start the app
  • Log into the app, and click the "Refresh entire application to test persistence" button (the app should load)
  • Uncomment line 12 in src/App.js and line 25 in src/components/Home.js (oktaAuth.start() and oktaAuth.stop())
  • Log into the app, and click the "Refresh entire application to test persistence" button (the app does not load)

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

If a user is already logged into the app and chooses to refresh the page for whatever reason, the user should continue to be logged in and should continue to see the content of the app on the screen.

Environment

  • Package version:
    •  {
         "@okta/okta-auth-js": "^5.5.0",
         "@okta/okta-react": "^6.2.0",
         "@okta/okta-signin-widget": "^5.2.2"
       }
  • React version:
    •  {
         "react": "^16.13.0",
         "react-dom": "^16.13.0",
         "react-router": "^5.2.0",
         "react-router-dom": "^5.2.0",
         "react-scripts": "4.0.3"
       }
  • Browser: Google Chrome
  • OS: MacOS 11.5.2
  • Node version (node -v): v14.16.0

Configuration

Okta SPA Setup:
Screen Shot 2021-10-06 at 2 03 31 PM

@denysoblohin-okta
Copy link
Contributor

Thanks for submitting this issue.
With okta-react you don't need to start service because it does it for you.

oktaAuth.start();

The source of your issue is as follows:

  • You call oktaAuth.start() in the beginning
  • The actual state is read from storage and is passed to handlers subscribed with oktaAuth.authStateManager.subscribe (okta-react's <Security/> component does this only in useEffect, so it misses state update this at this point)
  • useEffect is called for <Security/> which starts oktaAuth service and now subscribes to oktaAuth.authStateManager

Looks like the fix would be to call oktaAuth.authStateManager.getAuthState()) in useEffect of <Security/>

@denysoblohin-okta
Copy link
Contributor

Internal ref: OKTA-435836

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

No branches or pull requests

2 participants