@volr/react 0.1.2 → 0.1.3
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.cjs +29 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -7
- package/dist/index.d.ts +0 -7
- package/dist/index.js +29 -21
- package/dist/index.js.map +1 -1
- package/package.json +2 -3
package/dist/index.cjs
CHANGED
|
@@ -74,7 +74,7 @@ var safeStorage = {
|
|
|
74
74
|
}
|
|
75
75
|
};
|
|
76
76
|
|
|
77
|
-
//
|
|
77
|
+
// ../shared/src/constants/storage.ts
|
|
78
78
|
var STORAGE_KEYS = {
|
|
79
79
|
accessToken: "volr:accessToken",
|
|
80
80
|
user: "volr:user",
|
|
@@ -350,6 +350,17 @@ var SessionSync = class {
|
|
|
350
350
|
}
|
|
351
351
|
};
|
|
352
352
|
|
|
353
|
+
// src/config/backend.ts
|
|
354
|
+
var DEFAULT_API_BASE_URL = "https://api.volr.io";
|
|
355
|
+
function resolveApiBaseUrl(config) {
|
|
356
|
+
const anyConfig = config;
|
|
357
|
+
const override = anyConfig.apiBaseUrl;
|
|
358
|
+
if (override && typeof override === "string") {
|
|
359
|
+
return override.replace(/\/+$/, "");
|
|
360
|
+
}
|
|
361
|
+
return DEFAULT_API_BASE_URL;
|
|
362
|
+
}
|
|
363
|
+
|
|
353
364
|
// src/config/webauthn.ts
|
|
354
365
|
var AUTHENTICATOR_SELECTION = {
|
|
355
366
|
authenticatorAttachment: "platform",
|
|
@@ -649,18 +660,18 @@ function VolrProvider({ config, children }) {
|
|
|
649
660
|
providerCountRef.current--;
|
|
650
661
|
};
|
|
651
662
|
}, []);
|
|
663
|
+
const apiBaseUrl = resolveApiBaseUrl(config);
|
|
652
664
|
const client = react.useMemo(() => {
|
|
653
665
|
if (!config.projectApiKey) {
|
|
654
666
|
throw new Error(
|
|
655
667
|
"VolrProvider requires config.projectApiKey. Please set VITE_PROJECT_API_KEY environment variable or provide projectApiKey in config."
|
|
656
668
|
);
|
|
657
669
|
}
|
|
658
|
-
const baseUrl = config.__devApiBaseUrl || config.apiBaseUrl;
|
|
659
670
|
return new APIClient({
|
|
660
|
-
baseUrl,
|
|
671
|
+
baseUrl: apiBaseUrl,
|
|
661
672
|
apiKey: config.projectApiKey
|
|
662
673
|
});
|
|
663
|
-
}, [
|
|
674
|
+
}, [apiBaseUrl, config.projectApiKey]);
|
|
664
675
|
const [user, setUser] = react.useState(() => {
|
|
665
676
|
if (typeof window === "undefined") return null;
|
|
666
677
|
const userStr = safeStorage.getItem(STORAGE_KEYS.user);
|
|
@@ -1865,9 +1876,10 @@ function useVolrLogin() {
|
|
|
1865
1876
|
credentialId: u.credentialId ?? void 0
|
|
1866
1877
|
};
|
|
1867
1878
|
}, []);
|
|
1879
|
+
const apiBaseUrl = resolveApiBaseUrl(config);
|
|
1868
1880
|
const api = react.useMemo(
|
|
1869
|
-
() => createAxiosInstance(
|
|
1870
|
-
[
|
|
1881
|
+
() => createAxiosInstance(apiBaseUrl, config.projectApiKey),
|
|
1882
|
+
[apiBaseUrl, config.projectApiKey]
|
|
1871
1883
|
);
|
|
1872
1884
|
const requestEmailCode = react.useCallback(
|
|
1873
1885
|
async (email) => {
|
|
@@ -1935,11 +1947,11 @@ function useVolrLogin() {
|
|
|
1935
1947
|
const handleSocialLogin = react.useCallback(
|
|
1936
1948
|
async (provider) => {
|
|
1937
1949
|
if (typeof window !== "undefined") {
|
|
1938
|
-
const baseUrl =
|
|
1950
|
+
const baseUrl = apiBaseUrl.replace(/\/+$/, "");
|
|
1939
1951
|
window.location.href = `${baseUrl}/auth/${provider}`;
|
|
1940
1952
|
}
|
|
1941
1953
|
},
|
|
1942
|
-
[
|
|
1954
|
+
[apiBaseUrl]
|
|
1943
1955
|
);
|
|
1944
1956
|
const requestSiweNonce = react.useCallback(async () => {
|
|
1945
1957
|
const response = await api.get("/auth/siwe/nonce");
|
|
@@ -2033,6 +2045,7 @@ function useVolrAuthCallback(options = {}) {
|
|
|
2033
2045
|
credentialId: u.credentialId ?? void 0
|
|
2034
2046
|
};
|
|
2035
2047
|
}, []);
|
|
2048
|
+
const apiBaseUrl = resolveApiBaseUrl(config);
|
|
2036
2049
|
react.useEffect(() => {
|
|
2037
2050
|
const handleCallback = async () => {
|
|
2038
2051
|
if (typeof window === "undefined") return;
|
|
@@ -2059,7 +2072,7 @@ function useVolrAuthCallback(options = {}) {
|
|
|
2059
2072
|
setIsNewUser(isNew);
|
|
2060
2073
|
await refreshAccessToken();
|
|
2061
2074
|
const api = createAxiosInstance(
|
|
2062
|
-
|
|
2075
|
+
apiBaseUrl,
|
|
2063
2076
|
config.projectApiKey
|
|
2064
2077
|
);
|
|
2065
2078
|
const userRes = await api.get(`/auth/onboarding/${userId}`);
|
|
@@ -2087,7 +2100,7 @@ function useVolrAuthCallback(options = {}) {
|
|
|
2087
2100
|
}
|
|
2088
2101
|
};
|
|
2089
2102
|
handleCallback();
|
|
2090
|
-
}, [
|
|
2103
|
+
}, [apiBaseUrl, config.projectApiKey, refreshAccessToken, setAccessToken, setUser, toVolrUser]);
|
|
2091
2104
|
return {
|
|
2092
2105
|
isLoading,
|
|
2093
2106
|
error,
|
|
@@ -2388,6 +2401,7 @@ function usePasskeyEnrollment() {
|
|
|
2388
2401
|
const [isEnrolling, setIsEnrolling] = react.useState(false);
|
|
2389
2402
|
const [error, setError] = react.useState(null);
|
|
2390
2403
|
const isEnrollingRef = react.useRef(false);
|
|
2404
|
+
const apiBaseUrl = resolveApiBaseUrl(config);
|
|
2391
2405
|
const enroll = react.useCallback(async () => {
|
|
2392
2406
|
if (isEnrollingRef.current || isEnrolling) return;
|
|
2393
2407
|
isEnrollingRef.current = true;
|
|
@@ -2403,13 +2417,15 @@ function usePasskeyEnrollment() {
|
|
|
2403
2417
|
}
|
|
2404
2418
|
const accessToken = client.getAccessToken();
|
|
2405
2419
|
if (!accessToken) {
|
|
2406
|
-
throw new Error(
|
|
2420
|
+
throw new Error(
|
|
2421
|
+
"Access token is required for passkey enrollment. Please login first."
|
|
2422
|
+
);
|
|
2407
2423
|
}
|
|
2408
2424
|
const projectId = user.id;
|
|
2409
2425
|
setStep("encrypting");
|
|
2410
2426
|
const result = await enrollPasskey({
|
|
2411
2427
|
client,
|
|
2412
|
-
baseUrl:
|
|
2428
|
+
baseUrl: apiBaseUrl,
|
|
2413
2429
|
apiKey: config.projectApiKey,
|
|
2414
2430
|
userId: user.id,
|
|
2415
2431
|
userEmail: user.email,
|
|
@@ -2454,15 +2470,7 @@ function usePasskeyEnrollment() {
|
|
|
2454
2470
|
setIsEnrolling(false);
|
|
2455
2471
|
isEnrollingRef.current = false;
|
|
2456
2472
|
}
|
|
2457
|
-
}, [
|
|
2458
|
-
client,
|
|
2459
|
-
config.apiBaseUrl,
|
|
2460
|
-
config.projectApiKey,
|
|
2461
|
-
user,
|
|
2462
|
-
setProvider,
|
|
2463
|
-
setUser,
|
|
2464
|
-
isEnrolling
|
|
2465
|
-
]);
|
|
2473
|
+
}, [apiBaseUrl, client, config.projectApiKey, user, setProvider, setUser, isEnrolling]);
|
|
2466
2474
|
return {
|
|
2467
2475
|
enroll,
|
|
2468
2476
|
step,
|