@volr/react 0.1.2 → 0.1.4
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 +33 -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 +33 -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,21 @@ 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 devOverride = anyConfig.__devApiBaseUrl;
|
|
358
|
+
if (devOverride && typeof devOverride === "string") {
|
|
359
|
+
return devOverride.replace(/\/+$/, "");
|
|
360
|
+
}
|
|
361
|
+
const override = anyConfig.apiBaseUrl;
|
|
362
|
+
if (override && typeof override === "string") {
|
|
363
|
+
return override.replace(/\/+$/, "");
|
|
364
|
+
}
|
|
365
|
+
return DEFAULT_API_BASE_URL;
|
|
366
|
+
}
|
|
367
|
+
|
|
353
368
|
// src/config/webauthn.ts
|
|
354
369
|
var AUTHENTICATOR_SELECTION = {
|
|
355
370
|
authenticatorAttachment: "platform",
|
|
@@ -649,18 +664,18 @@ function VolrProvider({ config, children }) {
|
|
|
649
664
|
providerCountRef.current--;
|
|
650
665
|
};
|
|
651
666
|
}, []);
|
|
667
|
+
const apiBaseUrl = resolveApiBaseUrl(config);
|
|
652
668
|
const client = react.useMemo(() => {
|
|
653
669
|
if (!config.projectApiKey) {
|
|
654
670
|
throw new Error(
|
|
655
671
|
"VolrProvider requires config.projectApiKey. Please set VITE_PROJECT_API_KEY environment variable or provide projectApiKey in config."
|
|
656
672
|
);
|
|
657
673
|
}
|
|
658
|
-
const baseUrl = config.__devApiBaseUrl || config.apiBaseUrl;
|
|
659
674
|
return new APIClient({
|
|
660
|
-
baseUrl,
|
|
675
|
+
baseUrl: apiBaseUrl,
|
|
661
676
|
apiKey: config.projectApiKey
|
|
662
677
|
});
|
|
663
|
-
}, [
|
|
678
|
+
}, [apiBaseUrl, config.projectApiKey]);
|
|
664
679
|
const [user, setUser] = react.useState(() => {
|
|
665
680
|
if (typeof window === "undefined") return null;
|
|
666
681
|
const userStr = safeStorage.getItem(STORAGE_KEYS.user);
|
|
@@ -1865,9 +1880,10 @@ function useVolrLogin() {
|
|
|
1865
1880
|
credentialId: u.credentialId ?? void 0
|
|
1866
1881
|
};
|
|
1867
1882
|
}, []);
|
|
1883
|
+
const apiBaseUrl = resolveApiBaseUrl(config);
|
|
1868
1884
|
const api = react.useMemo(
|
|
1869
|
-
() => createAxiosInstance(
|
|
1870
|
-
[
|
|
1885
|
+
() => createAxiosInstance(apiBaseUrl, config.projectApiKey),
|
|
1886
|
+
[apiBaseUrl, config.projectApiKey]
|
|
1871
1887
|
);
|
|
1872
1888
|
const requestEmailCode = react.useCallback(
|
|
1873
1889
|
async (email) => {
|
|
@@ -1935,11 +1951,11 @@ function useVolrLogin() {
|
|
|
1935
1951
|
const handleSocialLogin = react.useCallback(
|
|
1936
1952
|
async (provider) => {
|
|
1937
1953
|
if (typeof window !== "undefined") {
|
|
1938
|
-
const baseUrl =
|
|
1954
|
+
const baseUrl = apiBaseUrl.replace(/\/+$/, "");
|
|
1939
1955
|
window.location.href = `${baseUrl}/auth/${provider}`;
|
|
1940
1956
|
}
|
|
1941
1957
|
},
|
|
1942
|
-
[
|
|
1958
|
+
[apiBaseUrl]
|
|
1943
1959
|
);
|
|
1944
1960
|
const requestSiweNonce = react.useCallback(async () => {
|
|
1945
1961
|
const response = await api.get("/auth/siwe/nonce");
|
|
@@ -2033,6 +2049,7 @@ function useVolrAuthCallback(options = {}) {
|
|
|
2033
2049
|
credentialId: u.credentialId ?? void 0
|
|
2034
2050
|
};
|
|
2035
2051
|
}, []);
|
|
2052
|
+
const apiBaseUrl = resolveApiBaseUrl(config);
|
|
2036
2053
|
react.useEffect(() => {
|
|
2037
2054
|
const handleCallback = async () => {
|
|
2038
2055
|
if (typeof window === "undefined") return;
|
|
@@ -2059,7 +2076,7 @@ function useVolrAuthCallback(options = {}) {
|
|
|
2059
2076
|
setIsNewUser(isNew);
|
|
2060
2077
|
await refreshAccessToken();
|
|
2061
2078
|
const api = createAxiosInstance(
|
|
2062
|
-
|
|
2079
|
+
apiBaseUrl,
|
|
2063
2080
|
config.projectApiKey
|
|
2064
2081
|
);
|
|
2065
2082
|
const userRes = await api.get(`/auth/onboarding/${userId}`);
|
|
@@ -2087,7 +2104,7 @@ function useVolrAuthCallback(options = {}) {
|
|
|
2087
2104
|
}
|
|
2088
2105
|
};
|
|
2089
2106
|
handleCallback();
|
|
2090
|
-
}, [
|
|
2107
|
+
}, [apiBaseUrl, config.projectApiKey, refreshAccessToken, setAccessToken, setUser, toVolrUser]);
|
|
2091
2108
|
return {
|
|
2092
2109
|
isLoading,
|
|
2093
2110
|
error,
|
|
@@ -2388,6 +2405,7 @@ function usePasskeyEnrollment() {
|
|
|
2388
2405
|
const [isEnrolling, setIsEnrolling] = react.useState(false);
|
|
2389
2406
|
const [error, setError] = react.useState(null);
|
|
2390
2407
|
const isEnrollingRef = react.useRef(false);
|
|
2408
|
+
const apiBaseUrl = resolveApiBaseUrl(config);
|
|
2391
2409
|
const enroll = react.useCallback(async () => {
|
|
2392
2410
|
if (isEnrollingRef.current || isEnrolling) return;
|
|
2393
2411
|
isEnrollingRef.current = true;
|
|
@@ -2403,13 +2421,15 @@ function usePasskeyEnrollment() {
|
|
|
2403
2421
|
}
|
|
2404
2422
|
const accessToken = client.getAccessToken();
|
|
2405
2423
|
if (!accessToken) {
|
|
2406
|
-
throw new Error(
|
|
2424
|
+
throw new Error(
|
|
2425
|
+
"Access token is required for passkey enrollment. Please login first."
|
|
2426
|
+
);
|
|
2407
2427
|
}
|
|
2408
2428
|
const projectId = user.id;
|
|
2409
2429
|
setStep("encrypting");
|
|
2410
2430
|
const result = await enrollPasskey({
|
|
2411
2431
|
client,
|
|
2412
|
-
baseUrl:
|
|
2432
|
+
baseUrl: apiBaseUrl,
|
|
2413
2433
|
apiKey: config.projectApiKey,
|
|
2414
2434
|
userId: user.id,
|
|
2415
2435
|
userEmail: user.email,
|
|
@@ -2454,15 +2474,7 @@ function usePasskeyEnrollment() {
|
|
|
2454
2474
|
setIsEnrolling(false);
|
|
2455
2475
|
isEnrollingRef.current = false;
|
|
2456
2476
|
}
|
|
2457
|
-
}, [
|
|
2458
|
-
client,
|
|
2459
|
-
config.apiBaseUrl,
|
|
2460
|
-
config.projectApiKey,
|
|
2461
|
-
user,
|
|
2462
|
-
setProvider,
|
|
2463
|
-
setUser,
|
|
2464
|
-
isEnrolling
|
|
2465
|
-
]);
|
|
2477
|
+
}, [apiBaseUrl, client, config.projectApiKey, user, setProvider, setUser, isEnrolling]);
|
|
2466
2478
|
return {
|
|
2467
2479
|
enroll,
|
|
2468
2480
|
step,
|