Refresh existing token


I’m seeking guidance rather than a technical answer at this point. I am using the @okta/okta-react package to create an auth flow. I can successfully login and logout no problems using the provided login/logout methods. This successfully creates a token in the localStorage`.

However, my application performs GraphQL requests and I would like to implement a flow for refreshing and retrieving tokens if a GQL request is in flight and the current token has expired. I do not want to force users to logout at this point, but refresh the existing token, if that is possible.

I have been following the docs for @okta/okta-auth-js, but am unclear as to which methods I should be using to refresh an existing token and retrieve a new/refreshed token, which will be used in my GQL requests.

There seem to be multiple paths, using session, token and tokenManager, but I’m not clear on which way is correct.

Could anyone advise:

  • Which method should I be using to access the exiting token in localStorage?
  • Which method should I be using to refresh that token?
  • How do I retrieve the new/refreshed token value
    Am I going about this completely wrong?


The issue appears to be when mixing the okta-react and okta-js packages. The usage of tokenManagerin okta-js doesn’t seem to correlate to the auth instance created using okta-react.

However, since scrapping okta-js, I can access a single auth instance using AuthManager from okta-react.

import { AuthService } from '@okta/okta-react';

const config = {}; // <- Your Okta config goes here
const authService = new AuthService({...config});
const accessToken = authService.getAccessToken();

authService.getAccessToken(); retrieves a token and handles token extension/refresh automatically.