@shopsbuilder/auth-sdk 1.2.7 → 1.2.8

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.
@@ -4,6 +4,7 @@ declare const getAccessTokenKey: (prefix?: string) => string;
4
4
  declare class SaleorAccessTokenStorageHandler {
5
5
  private storage;
6
6
  private prefix?;
7
+ private cachedToken;
7
8
  constructor(storage: StorageRepository, prefix?: string | undefined);
8
9
  getAccessToken: () => string | null;
9
10
  setAccessToken: (token: string) => void;
@@ -4,6 +4,7 @@ declare const getAccessTokenKey: (prefix?: string) => string;
4
4
  declare class SaleorAccessTokenStorageHandler {
5
5
  private storage;
6
6
  private prefix?;
7
+ private cachedToken;
7
8
  constructor(storage: StorageRepository, prefix?: string | undefined);
8
9
  getAccessToken: () => string | null;
9
10
  setAccessToken: (token: string) => void;
@@ -30,15 +30,22 @@ var SaleorAccessTokenStorageHandler = class {
30
30
  this.storage = storage;
31
31
  this.prefix = prefix;
32
32
  }
33
+ // In-memory cache so the token is available even when the storage
34
+ // backend is read-only (e.g. Next.js cookies during render).
35
+ cachedToken = null;
33
36
  getAccessToken = () => {
37
+ if (this.cachedToken)
38
+ return this.cachedToken;
34
39
  const key = getAccessTokenKey(this.prefix);
35
40
  return this.storage.getItem(key);
36
41
  };
37
42
  setAccessToken = (token) => {
43
+ this.cachedToken = token;
38
44
  const key = getAccessTokenKey(this.prefix);
39
45
  return this.storage.setItem(key, token);
40
46
  };
41
47
  clearAuthStorage = () => {
48
+ this.cachedToken = null;
42
49
  const key = getAccessTokenKey(this.prefix);
43
50
  return this.storage.removeItem(key);
44
51
  };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SaleorAccessTokenStorageHandler,
3
3
  getAccessTokenKey
4
- } from "./chunk-BZFBMGPG.mjs";
4
+ } from "./chunk-B326YIV6.mjs";
5
5
  export {
6
6
  SaleorAccessTokenStorageHandler,
7
7
  getAccessTokenKey
@@ -239,15 +239,22 @@ var SaleorAccessTokenStorageHandler = class {
239
239
  this.storage = storage;
240
240
  this.prefix = prefix;
241
241
  }
242
+ // In-memory cache so the token is available even when the storage
243
+ // backend is read-only (e.g. Next.js cookies during render).
244
+ cachedToken = null;
242
245
  getAccessToken = () => {
246
+ if (this.cachedToken)
247
+ return this.cachedToken;
243
248
  const key = getAccessTokenKey(this.prefix);
244
249
  return this.storage.getItem(key);
245
250
  };
246
251
  setAccessToken = (token) => {
252
+ this.cachedToken = token;
247
253
  const key = getAccessTokenKey(this.prefix);
248
254
  return this.storage.setItem(key, token);
249
255
  };
250
256
  clearAuthStorage = () => {
257
+ this.cachedToken = null;
251
258
  const key = getAccessTokenKey(this.prefix);
252
259
  return this.storage.removeItem(key);
253
260
  };
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  SaleorAuthClient,
3
3
  createSaleorAuthClient
4
- } from "./chunk-UHR2J6FG.mjs";
5
- import "./chunk-BZFBMGPG.mjs";
4
+ } from "./chunk-X3MKOESH.mjs";
5
+ import "./chunk-B326YIV6.mjs";
6
6
  import "./chunk-263DHBMK.mjs";
7
7
  import "./chunk-UDLCOX6B.mjs";
8
8
  import "./chunk-7JTFMRQS.mjs";
@@ -5,15 +5,22 @@ var SaleorAccessTokenStorageHandler = class {
5
5
  this.storage = storage;
6
6
  this.prefix = prefix;
7
7
  }
8
+ // In-memory cache so the token is available even when the storage
9
+ // backend is read-only (e.g. Next.js cookies during render).
10
+ cachedToken = null;
8
11
  getAccessToken = () => {
12
+ if (this.cachedToken)
13
+ return this.cachedToken;
9
14
  const key = getAccessTokenKey(this.prefix);
10
15
  return this.storage.getItem(key);
11
16
  };
12
17
  setAccessToken = (token) => {
18
+ this.cachedToken = token;
13
19
  const key = getAccessTokenKey(this.prefix);
14
20
  return this.storage.setItem(key, token);
15
21
  };
16
22
  clearAuthStorage = () => {
23
+ this.cachedToken = null;
17
24
  const key = getAccessTokenKey(this.prefix);
18
25
  return this.storage.removeItem(key);
19
26
  };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  SaleorAccessTokenStorageHandler
3
- } from "./chunk-BZFBMGPG.mjs";
3
+ } from "./chunk-B326YIV6.mjs";
4
4
  import {
5
5
  SaleorRefreshTokenStorageHandler
6
6
  } from "./chunk-263DHBMK.mjs";
package/dist/index.js CHANGED
@@ -242,15 +242,22 @@ var SaleorAccessTokenStorageHandler = class {
242
242
  this.storage = storage;
243
243
  this.prefix = prefix;
244
244
  }
245
+ // In-memory cache so the token is available even when the storage
246
+ // backend is read-only (e.g. Next.js cookies during render).
247
+ cachedToken = null;
245
248
  getAccessToken = () => {
249
+ if (this.cachedToken)
250
+ return this.cachedToken;
246
251
  const key = getAccessTokenKey(this.prefix);
247
252
  return this.storage.getItem(key);
248
253
  };
249
254
  setAccessToken = (token) => {
255
+ this.cachedToken = token;
250
256
  const key = getAccessTokenKey(this.prefix);
251
257
  return this.storage.setItem(key, token);
252
258
  };
253
259
  clearAuthStorage = () => {
260
+ this.cachedToken = null;
254
261
  const key = getAccessTokenKey(this.prefix);
255
262
  return this.storage.removeItem(key);
256
263
  };
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  SaleorAuthClient,
3
3
  createSaleorAuthClient
4
- } from "./chunk-UHR2J6FG.mjs";
5
- import "./chunk-BZFBMGPG.mjs";
4
+ } from "./chunk-X3MKOESH.mjs";
5
+ import "./chunk-B326YIV6.mjs";
6
6
  import "./chunk-263DHBMK.mjs";
7
7
  import {
8
8
  GraphQLError,
@@ -2,8 +2,8 @@ import {
2
2
  SaleorAuthProvider
3
3
  } from "../chunk-74GMXOK4.mjs";
4
4
  import "../chunk-NAQNA6DI.mjs";
5
- import "../chunk-UHR2J6FG.mjs";
6
- import "../chunk-BZFBMGPG.mjs";
5
+ import "../chunk-X3MKOESH.mjs";
6
+ import "../chunk-B326YIV6.mjs";
7
7
  import "../chunk-263DHBMK.mjs";
8
8
  import "../chunk-UDLCOX6B.mjs";
9
9
  import "../chunk-7JTFMRQS.mjs";
@@ -3,8 +3,8 @@ import {
3
3
  createSafeContext,
4
4
  useSaleorAuthContext
5
5
  } from "../chunk-NAQNA6DI.mjs";
6
- import "../chunk-UHR2J6FG.mjs";
7
- import "../chunk-BZFBMGPG.mjs";
6
+ import "../chunk-X3MKOESH.mjs";
7
+ import "../chunk-B326YIV6.mjs";
8
8
  import "../chunk-263DHBMK.mjs";
9
9
  import "../chunk-UDLCOX6B.mjs";
10
10
  import "../chunk-7JTFMRQS.mjs";
@@ -12,8 +12,8 @@ import {
12
12
  import {
13
13
  useSaleorExternalAuth
14
14
  } from "../chunk-Q3UFWDCC.mjs";
15
- import "../chunk-UHR2J6FG.mjs";
16
- import "../chunk-BZFBMGPG.mjs";
15
+ import "../chunk-X3MKOESH.mjs";
16
+ import "../chunk-B326YIV6.mjs";
17
17
  import "../chunk-263DHBMK.mjs";
18
18
  import "../chunk-T35JF4IS.mjs";
19
19
  import "../chunk-KLIEZ4V4.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopsbuilder/auth-sdk",
3
- "version": "1.2.7",
3
+ "version": "1.2.8",
4
4
  "description": "Auth SDK for Saleor",
5
5
  "sideEffects": false,
6
6
  "files": ["dist/", "README.md"],