Subscribes a callback that will be called when the authStateChange event happens. not triggering after 1hr token expiration
juztinlazaro opened this issue · 1 comments
juztinlazaro commented
Describe the bug
Subscribes a callback that will be called when the authStateChange event happens. not triggering after 1hr token expiration or idle mode
version:
"@okta/okta-auth-js": "7.8.1",
"@okta/okta-react": "6.9.0",
"@okta/okta-signin-widget": "7.24.2",
Reproduction Steps?
export const getOktaAuth = () => {
return new OktaAuth({
clientId: OKTA_CLIENT_ID,
redirectUri: `${window.location.origin}/authorization-code/callback`,
useClassicEngine: true,
issuer: `${OKTA_API_BASE}/oauth2/${OKTA_AUTH_SERVER}`,
pkce: true,
url: OKTA_API_BASE,
tokenManager: {
storageKey: 'mycrm-tokens',
},
transformAuthState: async (oktaAuth, authState) => {
if (!authState.isAuthenticated || !!authState.oktaUser) {
return authState;
}
const user = await oktaAuth.token.getUserInfo();
authState.isAuthenticated = !!user;
authState.oktaUser = user;
return authState;
},
});
};
export const onRefreshExpirationToken = async () => {
// trigger every 1hr
const oktaAuth = getOktaAuth();
oktaAuth.authStateManager.subscribe(async (authState) => {
console.log("authState==", authState);
if (authState.isAuthenticated) {
const newToken = authState.accessToken?.accessToken;
LocalStorageProxy.token = newToken;
}
});
oktaAuth.authStateManager.updateAuthState();
};
SDK Versions
version:
"@okta/okta-auth-js": "7.8.1",
"@okta/okta-react": "6.9.0",
"@okta/okta-signin-widget": "7.24.2",
```
### Additional Information?
_No response_
juztinlazaro commented
fixed by adding oktaAuth.start()
;
https://github.com/okta/okta-auth-js?tab=readme-ov-file#running-as-a-service