@volr/react 0.1.1 → 0.1.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.d.cts CHANGED
@@ -482,6 +482,18 @@ interface UseVolrLoginReturn {
482
482
  */
483
483
  declare function useVolrLogin(): UseVolrLoginReturn;
484
484
 
485
+ interface UseVolrAuthCallbackOptions {
486
+ onSuccess?: (user: VolrUser) => void;
487
+ onError?: (error: string) => void;
488
+ }
489
+ interface UseVolrAuthCallbackReturn {
490
+ isLoading: boolean;
491
+ error: string | null;
492
+ isNewUser: boolean;
493
+ user: VolrUser | null;
494
+ }
495
+ declare function useVolrAuthCallback(options?: UseVolrAuthCallbackOptions): UseVolrAuthCallbackReturn;
496
+
485
497
  type Erc20Token = {
486
498
  address: `0x${string}`;
487
499
  decimals: number;
@@ -637,4 +649,4 @@ declare function normalizeHex(value: `0x${string}` | string): `0x${string}`;
637
649
  */
638
650
  declare function normalizeHexArray(values: (`0x${string}` | string)[]): `0x${string}`[];
639
651
 
640
- export { type ApiResponse, type AuthRefreshResponseDto, type AuthResult, type BuildCallOptions, DEFAULT_EXPIRES_IN_SEC, DEFAULT_MODE, type DepositAsset$1 as DepositAsset, type DepositConfig, type Erc20Token$1 as Erc20Token, type KeyStorageType, type MpcConnectionStep, type NetworkDto, type NetworkInfo, type PasskeyAdapterOptions, type PasskeyEnrollmentStep, type PrfInputDto, type SendTxOptions, type SignerType, type SocialProvider, type TransactionDto, type TransactionStatus, type UseMpcConnectionReturn, type UsePasskeyEnrollmentReturn, type UsePrecheckReturn, type UseRelayReturn, type UseVolrLoginReturn, type UseVolrWalletReturn, type UserDto, type VolrConfig, type VolrContextValue, VolrProvider, type VolrUser, buildCall, buildCalls, createGetNetworkInfo, createPasskeyAdapter, defaultIdempotencyKey, normalizeHex, normalizeHexArray, uploadBlobViaPresign, useDepositListener, useInternalAuth, useMpcConnection, usePasskeyEnrollment, usePrecheck, useRelay, useVolr, useVolrLogin, useVolrWallet };
652
+ export { type ApiResponse, type AuthRefreshResponseDto, type AuthResult, type BuildCallOptions, DEFAULT_EXPIRES_IN_SEC, DEFAULT_MODE, type DepositAsset$1 as DepositAsset, type DepositConfig, type Erc20Token$1 as Erc20Token, type KeyStorageType, type MpcConnectionStep, type NetworkDto, type NetworkInfo, type PasskeyAdapterOptions, type PasskeyEnrollmentStep, type PrfInputDto, type SendTxOptions, type SignerType, type SocialProvider, type TransactionDto, type TransactionStatus, type UseMpcConnectionReturn, type UsePasskeyEnrollmentReturn, type UsePrecheckReturn, type UseRelayReturn, type UseVolrAuthCallbackOptions, type UseVolrAuthCallbackReturn, type UseVolrLoginReturn, type UseVolrWalletReturn, type UserDto, type VolrConfig, type VolrContextValue, VolrProvider, type VolrUser, buildCall, buildCalls, createGetNetworkInfo, createPasskeyAdapter, defaultIdempotencyKey, normalizeHex, normalizeHexArray, uploadBlobViaPresign, useDepositListener, useInternalAuth, useMpcConnection, usePasskeyEnrollment, usePrecheck, useRelay, useVolr, useVolrAuthCallback, useVolrLogin, useVolrWallet };
package/dist/index.d.ts CHANGED
@@ -482,6 +482,18 @@ interface UseVolrLoginReturn {
482
482
  */
483
483
  declare function useVolrLogin(): UseVolrLoginReturn;
484
484
 
485
+ interface UseVolrAuthCallbackOptions {
486
+ onSuccess?: (user: VolrUser) => void;
487
+ onError?: (error: string) => void;
488
+ }
489
+ interface UseVolrAuthCallbackReturn {
490
+ isLoading: boolean;
491
+ error: string | null;
492
+ isNewUser: boolean;
493
+ user: VolrUser | null;
494
+ }
495
+ declare function useVolrAuthCallback(options?: UseVolrAuthCallbackOptions): UseVolrAuthCallbackReturn;
496
+
485
497
  type Erc20Token = {
486
498
  address: `0x${string}`;
487
499
  decimals: number;
@@ -637,4 +649,4 @@ declare function normalizeHex(value: `0x${string}` | string): `0x${string}`;
637
649
  */
638
650
  declare function normalizeHexArray(values: (`0x${string}` | string)[]): `0x${string}`[];
639
651
 
640
- export { type ApiResponse, type AuthRefreshResponseDto, type AuthResult, type BuildCallOptions, DEFAULT_EXPIRES_IN_SEC, DEFAULT_MODE, type DepositAsset$1 as DepositAsset, type DepositConfig, type Erc20Token$1 as Erc20Token, type KeyStorageType, type MpcConnectionStep, type NetworkDto, type NetworkInfo, type PasskeyAdapterOptions, type PasskeyEnrollmentStep, type PrfInputDto, type SendTxOptions, type SignerType, type SocialProvider, type TransactionDto, type TransactionStatus, type UseMpcConnectionReturn, type UsePasskeyEnrollmentReturn, type UsePrecheckReturn, type UseRelayReturn, type UseVolrLoginReturn, type UseVolrWalletReturn, type UserDto, type VolrConfig, type VolrContextValue, VolrProvider, type VolrUser, buildCall, buildCalls, createGetNetworkInfo, createPasskeyAdapter, defaultIdempotencyKey, normalizeHex, normalizeHexArray, uploadBlobViaPresign, useDepositListener, useInternalAuth, useMpcConnection, usePasskeyEnrollment, usePrecheck, useRelay, useVolr, useVolrLogin, useVolrWallet };
652
+ export { type ApiResponse, type AuthRefreshResponseDto, type AuthResult, type BuildCallOptions, DEFAULT_EXPIRES_IN_SEC, DEFAULT_MODE, type DepositAsset$1 as DepositAsset, type DepositConfig, type Erc20Token$1 as Erc20Token, type KeyStorageType, type MpcConnectionStep, type NetworkDto, type NetworkInfo, type PasskeyAdapterOptions, type PasskeyEnrollmentStep, type PrfInputDto, type SendTxOptions, type SignerType, type SocialProvider, type TransactionDto, type TransactionStatus, type UseMpcConnectionReturn, type UsePasskeyEnrollmentReturn, type UsePrecheckReturn, type UseRelayReturn, type UseVolrAuthCallbackOptions, type UseVolrAuthCallbackReturn, type UseVolrLoginReturn, type UseVolrWalletReturn, type UserDto, type VolrConfig, type VolrContextValue, VolrProvider, type VolrUser, buildCall, buildCalls, createGetNetworkInfo, createPasskeyAdapter, defaultIdempotencyKey, normalizeHex, normalizeHexArray, uploadBlobViaPresign, useDepositListener, useInternalAuth, useMpcConnection, usePasskeyEnrollment, usePrecheck, useRelay, useVolr, useVolrAuthCallback, useVolrLogin, useVolrWallet };
package/dist/index.js CHANGED
@@ -2006,6 +2006,90 @@ function useVolrLogin() {
2006
2006
  handlePasskeyComplete
2007
2007
  };
2008
2008
  }
2009
+ function useVolrAuthCallback(options = {}) {
2010
+ const { config, setUser } = useVolr();
2011
+ const { refreshAccessToken, setAccessToken } = useInternalAuth();
2012
+ const [isLoading, setIsLoading] = useState(true);
2013
+ const [error, setError] = useState(null);
2014
+ const [isNewUser, setIsNewUser] = useState(false);
2015
+ const [user, setLocalUser] = useState(null);
2016
+ const toVolrUser = useCallback((u) => {
2017
+ return {
2018
+ id: u.id,
2019
+ email: u.email,
2020
+ accountId: u.accountId ?? void 0,
2021
+ evmAddress: u.evmAddress,
2022
+ keyStorageType: u.keyStorageType ?? void 0,
2023
+ signerType: u.signerType ?? void 0,
2024
+ walletConnector: u.walletConnector ?? void 0,
2025
+ lastWalletChainId: u.lastWalletChainId ?? void 0,
2026
+ blobUrl: u.blobUrl ?? void 0,
2027
+ prfInput: u.prfInput ?? void 0,
2028
+ credentialId: u.credentialId ?? void 0
2029
+ };
2030
+ }, []);
2031
+ useEffect(() => {
2032
+ const handleCallback = async () => {
2033
+ if (typeof window === "undefined") return;
2034
+ const searchParams = new URLSearchParams(window.location.search);
2035
+ const success = searchParams.get("success");
2036
+ const errorParam = searchParams.get("error");
2037
+ const userId = searchParams.get("userId");
2038
+ const isNew = searchParams.get("isNewUser") === "true";
2039
+ if (errorParam) {
2040
+ const errorMsg = `Authentication failed: ${errorParam}`;
2041
+ setError(errorMsg);
2042
+ setIsLoading(false);
2043
+ options.onError?.(errorMsg);
2044
+ return;
2045
+ }
2046
+ if (success !== "true" || !userId) {
2047
+ const errorMsg = "Invalid callback parameters";
2048
+ setError(errorMsg);
2049
+ setIsLoading(false);
2050
+ options.onError?.(errorMsg);
2051
+ return;
2052
+ }
2053
+ try {
2054
+ setIsNewUser(isNew);
2055
+ await refreshAccessToken();
2056
+ const api = createAxiosInstance(
2057
+ config.apiBaseUrl,
2058
+ config.projectApiKey
2059
+ );
2060
+ const userRes = await api.get(`/auth/onboarding/${userId}`);
2061
+ if (!userRes.data?.ok) {
2062
+ throw new Error("Failed to fetch user details");
2063
+ }
2064
+ const refreshRes = await api.post("/auth/refresh");
2065
+ if (!refreshRes.data?.ok) {
2066
+ throw new Error("Failed to refresh session");
2067
+ }
2068
+ const userData = refreshRes.data.data.user;
2069
+ const accessToken = refreshRes.data.data.accessToken;
2070
+ setAccessToken(accessToken);
2071
+ const volrUser = toVolrUser(userData);
2072
+ setUser(volrUser);
2073
+ setLocalUser(volrUser);
2074
+ setIsLoading(false);
2075
+ options.onSuccess?.(volrUser);
2076
+ } catch (err) {
2077
+ console.error("Callback error:", err);
2078
+ const errorMsg = err.message || "Failed to complete authentication";
2079
+ setError(errorMsg);
2080
+ setIsLoading(false);
2081
+ options.onError?.(errorMsg);
2082
+ }
2083
+ };
2084
+ handleCallback();
2085
+ }, [config.apiBaseUrl, config.projectApiKey, refreshAccessToken, setAccessToken, setUser, toVolrUser]);
2086
+ return {
2087
+ isLoading,
2088
+ error,
2089
+ isNewUser,
2090
+ user
2091
+ };
2092
+ }
2009
2093
  async function jsonRpc(rpcUrl, method, params) {
2010
2094
  const payload = {
2011
2095
  jsonrpc: "2.0",
@@ -2554,6 +2638,6 @@ async function uploadBlobViaPresign(params) {
2554
2638
  return { s3Key };
2555
2639
  }
2556
2640
 
2557
- export { DEFAULT_EXPIRES_IN_SEC, DEFAULT_MODE, VolrProvider, buildCall, buildCalls, createGetNetworkInfo, createPasskeyAdapter, defaultIdempotencyKey, normalizeHex, normalizeHexArray, uploadBlobViaPresign, useDepositListener, useInternalAuth, useMpcConnection, usePasskeyEnrollment, usePrecheck, useRelay, useVolr, useVolrLogin, useVolrWallet };
2641
+ export { DEFAULT_EXPIRES_IN_SEC, DEFAULT_MODE, VolrProvider, buildCall, buildCalls, createGetNetworkInfo, createPasskeyAdapter, defaultIdempotencyKey, normalizeHex, normalizeHexArray, uploadBlobViaPresign, useDepositListener, useInternalAuth, useMpcConnection, usePasskeyEnrollment, usePrecheck, useRelay, useVolr, useVolrAuthCallback, useVolrLogin, useVolrWallet };
2558
2642
  //# sourceMappingURL=index.js.map
2559
2643
  //# sourceMappingURL=index.js.map