@avalabs/avacloud-waas-react 1.0.0 → 1.0.2
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/dist/index.js +28 -17
- package/dist/index.mjs +23 -12
- package/package.json +8 -10
package/dist/index.js
CHANGED
|
@@ -79,7 +79,19 @@ function getDerivationPath(vm, accountIndex) {
|
|
|
79
79
|
|
|
80
80
|
// src/hooks/usePostMessage.ts
|
|
81
81
|
var import_react = require("react");
|
|
82
|
-
|
|
82
|
+
|
|
83
|
+
// src/constants/storage.ts
|
|
84
|
+
var OIDC_TOKEN_KEY = "avacloud-auth-oidc-token";
|
|
85
|
+
var AUTH_TOKENS_KEY = "auth_tokens";
|
|
86
|
+
var AUTH0_STORAGE_KEYS = {
|
|
87
|
+
IS_AUTHENTICATED: "auth0.is.authenticated",
|
|
88
|
+
ACCESS_TOKEN: "auth0.access_token",
|
|
89
|
+
ID_TOKEN: "auth0.id_token",
|
|
90
|
+
EXPIRES_AT: "auth0.expires_at"
|
|
91
|
+
};
|
|
92
|
+
var CUBIST_USER_ID_KEY = "cubist_user_id";
|
|
93
|
+
|
|
94
|
+
// src/hooks/usePostMessage.ts
|
|
83
95
|
function usePostMessage({
|
|
84
96
|
authServiceUrl,
|
|
85
97
|
orgId,
|
|
@@ -178,9 +190,9 @@ function usePostMessage({
|
|
|
178
190
|
}
|
|
179
191
|
} else {
|
|
180
192
|
setUser(null);
|
|
181
|
-
localStorage.removeItem(
|
|
182
|
-
localStorage.removeItem(
|
|
183
|
-
sessionStorage.removeItem(
|
|
193
|
+
localStorage.removeItem(AUTH_TOKENS_KEY);
|
|
194
|
+
localStorage.removeItem(AUTH0_STORAGE_KEYS.IS_AUTHENTICATED);
|
|
195
|
+
sessionStorage.removeItem(OIDC_TOKEN_KEY);
|
|
184
196
|
}
|
|
185
197
|
lastAuthStateRef.current = {
|
|
186
198
|
isAuthenticated: newIsAuthenticated,
|
|
@@ -190,7 +202,7 @@ function usePostMessage({
|
|
|
190
202
|
if (newIsAuthenticated && event.data.user) {
|
|
191
203
|
if (!hasRequestedOidcRef.current) {
|
|
192
204
|
if (event.data.tokens) {
|
|
193
|
-
localStorage.setItem(
|
|
205
|
+
localStorage.setItem(AUTH_TOKENS_KEY, JSON.stringify(event.data.tokens));
|
|
194
206
|
}
|
|
195
207
|
onAuthSuccess == null ? void 0 : onAuthSuccess();
|
|
196
208
|
}
|
|
@@ -209,7 +221,7 @@ function usePostMessage({
|
|
|
209
221
|
console.log("Registration successful:", event.data.payload);
|
|
210
222
|
const userId = (_f = event.data.payload) == null ? void 0 : _f.userId;
|
|
211
223
|
if (userId) {
|
|
212
|
-
localStorage.setItem(
|
|
224
|
+
localStorage.setItem(CUBIST_USER_ID_KEY, userId);
|
|
213
225
|
if (!hasRequestedOidcRef.current) {
|
|
214
226
|
console.log("Registration complete, sending GET_OIDC message");
|
|
215
227
|
hasRequestedOidcRef.current = true;
|
|
@@ -1181,7 +1193,6 @@ function ThemeProvider({ children, darkMode, onDarkModeChange }) {
|
|
|
1181
1193
|
}
|
|
1182
1194
|
|
|
1183
1195
|
// src/AvaCloudWalletProvider.tsx
|
|
1184
|
-
var import_waas_common2 = require("@avacloud/waas-common");
|
|
1185
1196
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1186
1197
|
var AvaCloudWalletContext = (0, import_react9.createContext)(void 0);
|
|
1187
1198
|
var queryClient = new import_react_query2.QueryClient({
|
|
@@ -1284,7 +1295,7 @@ function AvaCloudWalletProvider({
|
|
|
1284
1295
|
accessToken = oidcToken;
|
|
1285
1296
|
} else {
|
|
1286
1297
|
console.log("[loginWithCubist] Attempting to get OIDC token from localStorage.");
|
|
1287
|
-
const tokens = localStorage.getItem(
|
|
1298
|
+
const tokens = localStorage.getItem(AUTH_TOKENS_KEY);
|
|
1288
1299
|
if (!tokens) {
|
|
1289
1300
|
throw new Error("No authentication tokens found in localStorage");
|
|
1290
1301
|
}
|
|
@@ -1340,8 +1351,8 @@ function AvaCloudWalletProvider({
|
|
|
1340
1351
|
}
|
|
1341
1352
|
} catch (error) {
|
|
1342
1353
|
console.error("[loginWithCubist] Error during Cubist session creation/wallet info:", error);
|
|
1343
|
-
localStorage.removeItem(
|
|
1344
|
-
localStorage.removeItem(
|
|
1354
|
+
localStorage.removeItem(AUTH_TOKENS_KEY);
|
|
1355
|
+
localStorage.removeItem(AUTH0_STORAGE_KEYS.IS_AUTHENTICATED);
|
|
1345
1356
|
setIsAuthenticated(false);
|
|
1346
1357
|
setUser(null);
|
|
1347
1358
|
setCubistClient(null);
|
|
@@ -1435,13 +1446,13 @@ function AvaCloudWalletProvider({
|
|
|
1435
1446
|
setUser(null);
|
|
1436
1447
|
setWallet({ address: null });
|
|
1437
1448
|
setIsAuthenticated(false);
|
|
1438
|
-
localStorage.removeItem(
|
|
1439
|
-
localStorage.removeItem(
|
|
1440
|
-
localStorage.removeItem(
|
|
1441
|
-
localStorage.removeItem(
|
|
1442
|
-
localStorage.removeItem(
|
|
1443
|
-
localStorage.removeItem(
|
|
1444
|
-
sessionStorage.removeItem(
|
|
1449
|
+
localStorage.removeItem(AUTH_TOKENS_KEY);
|
|
1450
|
+
localStorage.removeItem(AUTH0_STORAGE_KEYS.IS_AUTHENTICATED);
|
|
1451
|
+
localStorage.removeItem(AUTH0_STORAGE_KEYS.ACCESS_TOKEN);
|
|
1452
|
+
localStorage.removeItem(AUTH0_STORAGE_KEYS.ID_TOKEN);
|
|
1453
|
+
localStorage.removeItem(AUTH0_STORAGE_KEYS.EXPIRES_AT);
|
|
1454
|
+
localStorage.removeItem(CUBIST_USER_ID_KEY);
|
|
1455
|
+
sessionStorage.removeItem(OIDC_TOKEN_KEY);
|
|
1445
1456
|
setCubistClient(null);
|
|
1446
1457
|
setCubistError(null);
|
|
1447
1458
|
setPendingOidcToken(null);
|
package/dist/index.mjs
CHANGED
|
@@ -33,7 +33,19 @@ function getDerivationPath(vm, accountIndex) {
|
|
|
33
33
|
|
|
34
34
|
// src/hooks/usePostMessage.ts
|
|
35
35
|
import { useCallback, useEffect, useRef } from "react";
|
|
36
|
-
|
|
36
|
+
|
|
37
|
+
// src/constants/storage.ts
|
|
38
|
+
var OIDC_TOKEN_KEY = "avacloud-auth-oidc-token";
|
|
39
|
+
var AUTH_TOKENS_KEY = "auth_tokens";
|
|
40
|
+
var AUTH0_STORAGE_KEYS = {
|
|
41
|
+
IS_AUTHENTICATED: "auth0.is.authenticated",
|
|
42
|
+
ACCESS_TOKEN: "auth0.access_token",
|
|
43
|
+
ID_TOKEN: "auth0.id_token",
|
|
44
|
+
EXPIRES_AT: "auth0.expires_at"
|
|
45
|
+
};
|
|
46
|
+
var CUBIST_USER_ID_KEY = "cubist_user_id";
|
|
47
|
+
|
|
48
|
+
// src/hooks/usePostMessage.ts
|
|
37
49
|
function usePostMessage({
|
|
38
50
|
authServiceUrl,
|
|
39
51
|
orgId,
|
|
@@ -1135,7 +1147,6 @@ function ThemeProvider({ children, darkMode, onDarkModeChange }) {
|
|
|
1135
1147
|
}
|
|
1136
1148
|
|
|
1137
1149
|
// src/AvaCloudWalletProvider.tsx
|
|
1138
|
-
import { AUTH_TOKENS_KEY as AUTH_TOKENS_KEY2, OIDC_TOKEN_KEY as OIDC_TOKEN_KEY2, AUTH0_STORAGE_KEYS as AUTH0_STORAGE_KEYS2, CUBIST_USER_ID_KEY as CUBIST_USER_ID_KEY2 } from "@avacloud/waas-common";
|
|
1139
1150
|
import { Fragment, jsx as jsx7 } from "react/jsx-runtime";
|
|
1140
1151
|
var AvaCloudWalletContext = createContext4(void 0);
|
|
1141
1152
|
var queryClient = new QueryClient({
|
|
@@ -1238,7 +1249,7 @@ function AvaCloudWalletProvider({
|
|
|
1238
1249
|
accessToken = oidcToken;
|
|
1239
1250
|
} else {
|
|
1240
1251
|
console.log("[loginWithCubist] Attempting to get OIDC token from localStorage.");
|
|
1241
|
-
const tokens = localStorage.getItem(
|
|
1252
|
+
const tokens = localStorage.getItem(AUTH_TOKENS_KEY);
|
|
1242
1253
|
if (!tokens) {
|
|
1243
1254
|
throw new Error("No authentication tokens found in localStorage");
|
|
1244
1255
|
}
|
|
@@ -1294,8 +1305,8 @@ function AvaCloudWalletProvider({
|
|
|
1294
1305
|
}
|
|
1295
1306
|
} catch (error) {
|
|
1296
1307
|
console.error("[loginWithCubist] Error during Cubist session creation/wallet info:", error);
|
|
1297
|
-
localStorage.removeItem(
|
|
1298
|
-
localStorage.removeItem(
|
|
1308
|
+
localStorage.removeItem(AUTH_TOKENS_KEY);
|
|
1309
|
+
localStorage.removeItem(AUTH0_STORAGE_KEYS.IS_AUTHENTICATED);
|
|
1299
1310
|
setIsAuthenticated(false);
|
|
1300
1311
|
setUser(null);
|
|
1301
1312
|
setCubistClient(null);
|
|
@@ -1389,13 +1400,13 @@ function AvaCloudWalletProvider({
|
|
|
1389
1400
|
setUser(null);
|
|
1390
1401
|
setWallet({ address: null });
|
|
1391
1402
|
setIsAuthenticated(false);
|
|
1392
|
-
localStorage.removeItem(
|
|
1393
|
-
localStorage.removeItem(
|
|
1394
|
-
localStorage.removeItem(
|
|
1395
|
-
localStorage.removeItem(
|
|
1396
|
-
localStorage.removeItem(
|
|
1397
|
-
localStorage.removeItem(
|
|
1398
|
-
sessionStorage.removeItem(
|
|
1403
|
+
localStorage.removeItem(AUTH_TOKENS_KEY);
|
|
1404
|
+
localStorage.removeItem(AUTH0_STORAGE_KEYS.IS_AUTHENTICATED);
|
|
1405
|
+
localStorage.removeItem(AUTH0_STORAGE_KEYS.ACCESS_TOKEN);
|
|
1406
|
+
localStorage.removeItem(AUTH0_STORAGE_KEYS.ID_TOKEN);
|
|
1407
|
+
localStorage.removeItem(AUTH0_STORAGE_KEYS.EXPIRES_AT);
|
|
1408
|
+
localStorage.removeItem(CUBIST_USER_ID_KEY);
|
|
1409
|
+
sessionStorage.removeItem(OIDC_TOKEN_KEY);
|
|
1399
1410
|
setCubistClient(null);
|
|
1400
1411
|
setCubistError(null);
|
|
1401
1412
|
setPendingOidcToken(null);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@avalabs/avacloud-waas-react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "React SDK for AvaCloud Wallet as a Service",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -10,13 +10,6 @@
|
|
|
10
10
|
"files": [
|
|
11
11
|
"dist/**"
|
|
12
12
|
],
|
|
13
|
-
"scripts": {
|
|
14
|
-
"build": "tsup src/index.ts --format esm,cjs --dts --external react",
|
|
15
|
-
"dev": "tsup src/index.ts --format esm,cjs --watch --dts --external react",
|
|
16
|
-
"lint": "eslint \"src/**/*.ts*\"",
|
|
17
|
-
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
|
|
18
|
-
"prepublishOnly": "npm run build"
|
|
19
|
-
},
|
|
20
13
|
"devDependencies": {
|
|
21
14
|
"@iconify/types": "^2.0.0",
|
|
22
15
|
"@types/react": "^18.2.46",
|
|
@@ -31,7 +24,6 @@
|
|
|
31
24
|
"react-dom": "^17.0.0 || ^18.0.0"
|
|
32
25
|
},
|
|
33
26
|
"dependencies": {
|
|
34
|
-
"@avacloud/waas-common": "workspace:*",
|
|
35
27
|
"@avalabs/core-k2-components": "4.18.0-alpha.52",
|
|
36
28
|
"@cubist-labs/cubesigner-sdk": "0.4.110-0",
|
|
37
29
|
"@iconify/react": "^4.1.1",
|
|
@@ -57,5 +49,11 @@
|
|
|
57
49
|
"url": "https://github.com/ava-labs/avacloud-auth-react/issues"
|
|
58
50
|
},
|
|
59
51
|
"homepage": "https://github.com/ava-labs/avacloud-auth-react#readme",
|
|
60
|
-
"author": "Ava Labs, Inc."
|
|
52
|
+
"author": "Ava Labs, Inc.",
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --external react",
|
|
55
|
+
"dev": "tsup src/index.ts --format esm,cjs --watch --dts --external react",
|
|
56
|
+
"lint": "eslint \"src/**/*.ts*\"",
|
|
57
|
+
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
|
|
58
|
+
}
|
|
61
59
|
}
|