I'm submitting this issue for the package(s):
I'm submitting a:
Current behavior
I've noticed that the Security component creates a new instance of AuthService after every rendering. Potentially it could cause a lot of different concurrency issues but right now I found issue in token renew functionality. If the application renders multiple times the Security component than during token renew it will send multiple requests to the token endpoint:


I see that you tried to prevent such behaviour with useMemo but the problem is that useMemo compares dependencies by referential equality. When application renders the component it gets a new object of the properties. Props could have the same attributes but for every render, it is a new Object. Like {} === {} returns false.
Expected behavior
I would expect to have one instance of AuthService to prevent multiple calls to API. I think there a few ways to fix it. One of them is to use a Singletone pattern for service creation and do a deep check of props before creating the new instance.
Minimal reproduction of the problem with instructions
To reproduce the issue with token auto-renew you can just get this sample https://github.com/okta/samples-js-react/tree/master/okta-hosted-login. You need to render https://github.com/okta/samples-js-react/blob/master/okta-hosted-login/src/App.jsx for multiple times so you can use a timer or add a button which will change the state of the component after every click

In config enable autoRenew:
tokenManager: {
storage: 'sessionStorage',
autoRenew: true
}
If you don't want to wait one hour for session expiration you can change manually value of expiresAt for idToken and accessToken in session storage okta-token-storage and refresh the page to read new values by application. For calculating expiresAt you can use this code: Math.round((new Date().getTime() + 1000 * 60 * 2 )/ 1000) It returns expiresAt value for 2 minutes later.
Render the component multiple times after refreshing by clicking the button and you will see multiple requests for token renew after one minute and a half.
Extra information about the use case/user story you are trying to implement
Temporary workaround for dealing with this issue is to prevent multiple rendering of Security component.
Environment
- Package Version: "@okta/okta-react": "3.0.7",
- Browser: Chrome
- OS: macOS Catalina
- Node version (
node -v): v12.18.3
- Other:
I'm submitting this issue for the package(s):
I'm submitting a:
Current behavior
I've noticed that the Security component creates a new instance of AuthService after every rendering. Potentially it could cause a lot of different concurrency issues but right now I found issue in token renew functionality. If the application renders multiple times the Security component than during token renew it will send multiple requests to the token endpoint:


I see that you tried to prevent such behaviour with
useMemobut the problem is thatuseMemocompares dependencies by referential equality. When application renders the component it gets a new object of the properties. Props could have the same attributes but for every render, it is a new Object. Like{} === {}returns false.Expected behavior
I would expect to have one instance of AuthService to prevent multiple calls to API. I think there a few ways to fix it. One of them is to use a Singletone pattern for service creation and do a deep check of props before creating the new instance.
Minimal reproduction of the problem with instructions
To reproduce the issue with token auto-renew you can just get this sample https://github.com/okta/samples-js-react/tree/master/okta-hosted-login. You need to render https://github.com/okta/samples-js-react/blob/master/okta-hosted-login/src/App.jsx for multiple times so you can use a timer or add a button which will change the state of the component after every click

In config enable autoRenew:
If you don't want to wait one hour for session expiration you can change manually value of
expiresAtforidTokenandaccessTokenin session storageokta-token-storageand refresh the page to read new values by application. For calculatingexpiresAtyou can use this code:Math.round((new Date().getTime() + 1000 * 60 * 2 )/ 1000)It returnsexpiresAtvalue for 2 minutes later.Render the component multiple times after refreshing by clicking the button and you will see multiple requests for token renew after one minute and a half.
Extra information about the use case/user story you are trying to implement
Temporary workaround for dealing with this issue is to prevent multiple rendering of
Securitycomponent.Environment
node -v): v12.18.3