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

Issue with clearing cache #8

Open
alexpchin opened this issue Apr 26, 2022 · 0 comments
Open

Issue with clearing cache #8

alexpchin opened this issue Apr 26, 2022 · 0 comments

Comments

@alexpchin
Copy link

Hello, I've just implemented this library and I believe there is an issue with clearing the internal cache after logging out. I've added a force clear cache to be able to be cleared on Logout:

diff --git a/node_modules/apollo-link-jwt/lib/index.js b/node_modules/apollo-link-jwt/lib/index.js
index 03e1c12..7928e0b 100644
--- a/node_modules/apollo-link-jwt/lib/index.js
+++ b/node_modules/apollo-link-jwt/lib/index.js
@@ -7,6 +7,17 @@ import { addRefreshTokenToBody } from './add-refresh-token-to-body';
 import { isJwtExpired } from './is-jwt-expired';
 import { fetchData } from './fetch-data';
 
+/**
+ * Global cached tokens to prevent an expensive Async lookup on every request
+ */
+let cachedAccessToken = null;
+let cachedRefreshToken = null;
+
+export const forceClearCache = () => {
+  cachedAccessToken = null;
+  cachedRefreshToken = null;
+}
+
 export const ApolloLinkJWT = ({
   apiUrl,
   getTokens,
@@ -15,12 +26,6 @@ export const ApolloLinkJWT = ({
   onRefreshComplete,
   debugMode = false,
 }) => {
-  /**
-   * Global cached tokens to prevent an expensive Async lookup on every request
-   */
-  let cachedAccessToken = null;
-  let cachedRefreshToken = null;
-
   /**
    * Resets the internally cached values
    */
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

1 participant