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

Subscribes a callback that will be called when the authStateChange event happens. not triggering after 1hr token expiration #1548

Open
juztinlazaro opened this issue Oct 24, 2024 · 1 comment
Labels

Comments

@juztinlazaro
Copy link

juztinlazaro commented Oct 24, 2024

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
Copy link
Author

juztinlazaro commented Oct 30, 2024

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

No branches or pull requests

1 participant