@logto/client 2.6.4 → 2.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.cjs CHANGED
@@ -57,6 +57,14 @@ class StandardLogtoClient {
57
57
  * It uses the same refresh strategy as {@link getAccessToken}.
58
58
  */
59
59
  this.getOrganizationToken = memoize.memoize(this.#getOrganizationToken);
60
+ /**
61
+ * Clear the access token from the cache storage.
62
+ */
63
+ this.clearAccessToken = memoize.memoize(this.#clearAccessToken);
64
+ /**
65
+ * Clear all cached tokens from storage.
66
+ */
67
+ this.clearAllTokens = memoize.memoize(this.#clearAllTokens);
60
68
  /**
61
69
  * Handle the sign-in callback by parsing the authorization code from the
62
70
  * callback URI and exchanging it for the tokens.
@@ -179,9 +187,7 @@ class StandardLogtoClient {
179
187
  });
180
188
  await Promise.all([
181
189
  this.setSignInSession({ redirectUri, postRedirectUri, codeVerifier, state }),
182
- this.setRefreshToken(null),
183
- this.setIdToken(null),
184
- this.clearAccessToken(),
190
+ this.clearAllTokens(),
185
191
  ]);
186
192
  await this.adapter.navigate(signInUri, { redirectUri, for: 'sign-in' });
187
193
  }
@@ -229,7 +235,7 @@ class StandardLogtoClient {
229
235
  postLogoutRedirectUri,
230
236
  clientId,
231
237
  });
232
- await Promise.all([this.setRefreshToken(null), this.setIdToken(null), this.clearAccessToken()]);
238
+ await this.clearAllTokens();
233
239
  await this.adapter.navigate(url, { redirectUri: postLogoutRedirectUri, for: 'sign-out' });
234
240
  }
235
241
  async getSignInSession() {
@@ -252,10 +258,6 @@ class StandardLogtoClient {
252
258
  async setRefreshToken(value) {
253
259
  return this.adapter.setStorageItem(types.PersistKey.RefreshToken, value);
254
260
  }
255
- async clearAccessToken() {
256
- this.accessTokenMap.clear();
257
- await this.adapter.storage.removeItem('accessToken');
258
- }
259
261
  async getAccessTokenByRefreshToken(resource, organizationId) {
260
262
  const currentRefreshToken = await this.getRefreshToken();
261
263
  if (!currentRefreshToken) {
@@ -347,6 +349,13 @@ class StandardLogtoClient {
347
349
  }
348
350
  return this.getAccessToken(undefined, organizationId);
349
351
  }
352
+ async #clearAccessToken() {
353
+ this.accessTokenMap.clear();
354
+ await this.adapter.storage.removeItem('accessToken');
355
+ }
356
+ async #clearAllTokens() {
357
+ await Promise.all([this.setRefreshToken(null), this.setIdToken(null), this.clearAccessToken()]);
358
+ }
350
359
  async #handleSignInCallback(callbackUri) {
351
360
  const signInSession = await this.getSignInSession();
352
361
  if (!signInSession) {
package/lib/client.d.ts CHANGED
@@ -66,6 +66,14 @@ export declare class StandardLogtoClient {
66
66
  * It uses the same refresh strategy as {@link getAccessToken}.
67
67
  */
68
68
  readonly getOrganizationToken: (this: unknown, organizationId: string) => Promise<string>;
69
+ /**
70
+ * Clear the access token from the cache storage.
71
+ */
72
+ readonly clearAccessToken: (this: unknown) => Promise<void>;
73
+ /**
74
+ * Clear all cached tokens from storage.
75
+ */
76
+ readonly clearAllTokens: (this: unknown) => Promise<void>;
69
77
  /**
70
78
  * Handle the sign-in callback by parsing the authorization code from the
71
79
  * callback URI and exchanging it for the tokens.
@@ -188,7 +196,6 @@ export declare class StandardLogtoClient {
188
196
  protected setSignInSession(value: Nullable<LogtoSignInSessionItem>): Promise<void>;
189
197
  private setIdToken;
190
198
  private setRefreshToken;
191
- private clearAccessToken;
192
199
  private getAccessTokenByRefreshToken;
193
200
  private saveAccessTokenMap;
194
201
  private loadAccessTokenMap;
package/lib/client.js CHANGED
@@ -55,6 +55,14 @@ class StandardLogtoClient {
55
55
  * It uses the same refresh strategy as {@link getAccessToken}.
56
56
  */
57
57
  this.getOrganizationToken = memoize(this.#getOrganizationToken);
58
+ /**
59
+ * Clear the access token from the cache storage.
60
+ */
61
+ this.clearAccessToken = memoize(this.#clearAccessToken);
62
+ /**
63
+ * Clear all cached tokens from storage.
64
+ */
65
+ this.clearAllTokens = memoize(this.#clearAllTokens);
58
66
  /**
59
67
  * Handle the sign-in callback by parsing the authorization code from the
60
68
  * callback URI and exchanging it for the tokens.
@@ -177,9 +185,7 @@ class StandardLogtoClient {
177
185
  });
178
186
  await Promise.all([
179
187
  this.setSignInSession({ redirectUri, postRedirectUri, codeVerifier, state }),
180
- this.setRefreshToken(null),
181
- this.setIdToken(null),
182
- this.clearAccessToken(),
188
+ this.clearAllTokens(),
183
189
  ]);
184
190
  await this.adapter.navigate(signInUri, { redirectUri, for: 'sign-in' });
185
191
  }
@@ -227,7 +233,7 @@ class StandardLogtoClient {
227
233
  postLogoutRedirectUri,
228
234
  clientId,
229
235
  });
230
- await Promise.all([this.setRefreshToken(null), this.setIdToken(null), this.clearAccessToken()]);
236
+ await this.clearAllTokens();
231
237
  await this.adapter.navigate(url, { redirectUri: postLogoutRedirectUri, for: 'sign-out' });
232
238
  }
233
239
  async getSignInSession() {
@@ -250,10 +256,6 @@ class StandardLogtoClient {
250
256
  async setRefreshToken(value) {
251
257
  return this.adapter.setStorageItem(PersistKey.RefreshToken, value);
252
258
  }
253
- async clearAccessToken() {
254
- this.accessTokenMap.clear();
255
- await this.adapter.storage.removeItem('accessToken');
256
- }
257
259
  async getAccessTokenByRefreshToken(resource, organizationId) {
258
260
  const currentRefreshToken = await this.getRefreshToken();
259
261
  if (!currentRefreshToken) {
@@ -345,6 +347,13 @@ class StandardLogtoClient {
345
347
  }
346
348
  return this.getAccessToken(undefined, organizationId);
347
349
  }
350
+ async #clearAccessToken() {
351
+ this.accessTokenMap.clear();
352
+ await this.adapter.storage.removeItem('accessToken');
353
+ }
354
+ async #clearAllTokens() {
355
+ await Promise.all([this.setRefreshToken(null), this.setIdToken(null), this.clearAccessToken()]);
356
+ }
348
357
  async #handleSignInCallback(callbackUri) {
349
358
  const signInSession = await this.getSignInSession();
350
359
  if (!signInSession) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logto/client",
3
- "version": "2.6.4",
3
+ "version": "2.6.6",
4
4
  "type": "module",
5
5
  "main": "./lib/index.cjs",
6
6
  "module": "./lib/index.js",