@arcote.tech/arc 0.4.7 → 0.4.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.
Files changed (2) hide show
  1. package/dist/index.js +13 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -3,14 +3,23 @@ var TOKEN_PREFIX = "arc:token:";
3
3
  function hasLocalStorage() {
4
4
  return typeof localStorage !== "undefined";
5
5
  }
6
+ function notifyTokenChange(scope) {
7
+ if (typeof window !== "undefined") {
8
+ queueMicrotask(() => {
9
+ window.dispatchEvent(new CustomEvent("arc:token-change", { detail: { scope } }));
10
+ });
11
+ }
12
+ }
6
13
 
7
14
  class AuthAdapter {
8
15
  scopes = new Map;
9
16
  setToken(token, scope = "default") {
10
17
  if (!token) {
11
18
  this.scopes.delete(scope);
12
- if (hasLocalStorage())
19
+ if (hasLocalStorage()) {
13
20
  localStorage.removeItem(TOKEN_PREFIX + scope);
21
+ notifyTokenChange(scope);
22
+ }
14
23
  return;
15
24
  }
16
25
  try {
@@ -31,8 +40,10 @@ class AuthAdapter {
31
40
  exp: payload.exp
32
41
  }
33
42
  });
34
- if (hasLocalStorage())
43
+ if (hasLocalStorage()) {
35
44
  localStorage.setItem(TOKEN_PREFIX + scope, token);
45
+ notifyTokenChange(scope);
46
+ }
36
47
  } catch {
37
48
  this.scopes.delete(scope);
38
49
  if (hasLocalStorage())
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@arcote.tech/arc",
3
3
  "type": "module",
4
- "version": "0.4.7",
4
+ "version": "0.4.8",
5
5
  "private": false,
6
6
  "author": "Przemysław Krasiński [arcote.tech]",
7
7
  "description": "Arc framework core rewrite with improved event emission and type safety",