@volr/react 0.1.0 → 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/README.md +33 -11
- package/dist/index.cjs +85 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +85 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,11 +19,8 @@ function App() {
|
|
|
19
19
|
return (
|
|
20
20
|
<VolrProvider
|
|
21
21
|
config={{
|
|
22
|
-
apiBaseUrl: 'https://api.volr.io',
|
|
23
22
|
defaultChainId: 8453,
|
|
24
|
-
|
|
25
|
-
8453: '0x...',
|
|
26
|
-
},
|
|
23
|
+
projectApiKey: 'your-project-api-key',
|
|
27
24
|
}}
|
|
28
25
|
>
|
|
29
26
|
<YourApp />
|
|
@@ -91,6 +88,38 @@ function AdvancedComponent() {
|
|
|
91
88
|
- **SSR Safe**: Works with Next.js and other SSR frameworks
|
|
92
89
|
- **Call Builders**: `buildCall()` and `buildCalls()` utilities for easy transaction building
|
|
93
90
|
|
|
91
|
+
## OAuth Handling
|
|
92
|
+
|
|
93
|
+
The SDK provides a dedicated hook `useVolrAuthCallback` to simplify handling OAuth redirects. This is useful for custom login flows where you need to process the callback from social providers (Google, Twitter, Apple).
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
import { useVolrAuthCallback } from '@volr/react';
|
|
97
|
+
|
|
98
|
+
function AuthCallback() {
|
|
99
|
+
const { isLoading, error, isNewUser, user } = useVolrAuthCallback({
|
|
100
|
+
onSuccess: (user) => {
|
|
101
|
+
console.log('Logged in:', user);
|
|
102
|
+
// Navigate to dashboard or home
|
|
103
|
+
},
|
|
104
|
+
onError: (err) => {
|
|
105
|
+
console.error('Login failed:', err);
|
|
106
|
+
// Show error message or redirect to login
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
if (isLoading) return <div>Processing authentication...</div>;
|
|
111
|
+
if (error) return <div>Error: {error}</div>;
|
|
112
|
+
|
|
113
|
+
return <div>Redirecting...</div>;
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
This hook automatically:
|
|
118
|
+
1. Parses URL parameters (`success`, `userId`, `isNewUser`, `error`)
|
|
119
|
+
2. Refreshes the session to establish the authentication cookie
|
|
120
|
+
3. Fetches the full user profile
|
|
121
|
+
4. Updates the global `VolrProvider` context state
|
|
122
|
+
|
|
94
123
|
## Failure Semantics
|
|
95
124
|
|
|
96
125
|
- Relay enforces strict failure-by-default:
|
|
@@ -115,10 +144,3 @@ The SDK surfaces these in console for convenience:
|
|
|
115
144
|
- Relay errors: `[volr][relay] developerDiagnostics: ...`
|
|
116
145
|
|
|
117
146
|
Use these to pinpoint which call failed and why (e.g., EOA target, ERC20 returned false, custom revert).
|
|
118
|
-
|
|
119
|
-
## Documentation
|
|
120
|
-
|
|
121
|
-
- **[React Integration Guide](./REACT_INTEGRATION.md)** - Complete guide for integrating Volr React SDK
|
|
122
|
-
- **[Contract Integration Guide](../CONTRACT_INTEGRATION.md)** - Guide for SDK engineers
|
|
123
|
-
- [Volr Documentation](https://docs.volr.io) - Detailed API reference
|
|
124
|
-
|
package/dist/index.cjs
CHANGED
|
@@ -2011,6 +2011,90 @@ function useVolrLogin() {
|
|
|
2011
2011
|
handlePasskeyComplete
|
|
2012
2012
|
};
|
|
2013
2013
|
}
|
|
2014
|
+
function useVolrAuthCallback(options = {}) {
|
|
2015
|
+
const { config, setUser } = useVolr();
|
|
2016
|
+
const { refreshAccessToken, setAccessToken } = useInternalAuth();
|
|
2017
|
+
const [isLoading, setIsLoading] = react.useState(true);
|
|
2018
|
+
const [error, setError] = react.useState(null);
|
|
2019
|
+
const [isNewUser, setIsNewUser] = react.useState(false);
|
|
2020
|
+
const [user, setLocalUser] = react.useState(null);
|
|
2021
|
+
const toVolrUser = react.useCallback((u) => {
|
|
2022
|
+
return {
|
|
2023
|
+
id: u.id,
|
|
2024
|
+
email: u.email,
|
|
2025
|
+
accountId: u.accountId ?? void 0,
|
|
2026
|
+
evmAddress: u.evmAddress,
|
|
2027
|
+
keyStorageType: u.keyStorageType ?? void 0,
|
|
2028
|
+
signerType: u.signerType ?? void 0,
|
|
2029
|
+
walletConnector: u.walletConnector ?? void 0,
|
|
2030
|
+
lastWalletChainId: u.lastWalletChainId ?? void 0,
|
|
2031
|
+
blobUrl: u.blobUrl ?? void 0,
|
|
2032
|
+
prfInput: u.prfInput ?? void 0,
|
|
2033
|
+
credentialId: u.credentialId ?? void 0
|
|
2034
|
+
};
|
|
2035
|
+
}, []);
|
|
2036
|
+
react.useEffect(() => {
|
|
2037
|
+
const handleCallback = async () => {
|
|
2038
|
+
if (typeof window === "undefined") return;
|
|
2039
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
2040
|
+
const success = searchParams.get("success");
|
|
2041
|
+
const errorParam = searchParams.get("error");
|
|
2042
|
+
const userId = searchParams.get("userId");
|
|
2043
|
+
const isNew = searchParams.get("isNewUser") === "true";
|
|
2044
|
+
if (errorParam) {
|
|
2045
|
+
const errorMsg = `Authentication failed: ${errorParam}`;
|
|
2046
|
+
setError(errorMsg);
|
|
2047
|
+
setIsLoading(false);
|
|
2048
|
+
options.onError?.(errorMsg);
|
|
2049
|
+
return;
|
|
2050
|
+
}
|
|
2051
|
+
if (success !== "true" || !userId) {
|
|
2052
|
+
const errorMsg = "Invalid callback parameters";
|
|
2053
|
+
setError(errorMsg);
|
|
2054
|
+
setIsLoading(false);
|
|
2055
|
+
options.onError?.(errorMsg);
|
|
2056
|
+
return;
|
|
2057
|
+
}
|
|
2058
|
+
try {
|
|
2059
|
+
setIsNewUser(isNew);
|
|
2060
|
+
await refreshAccessToken();
|
|
2061
|
+
const api = createAxiosInstance(
|
|
2062
|
+
config.apiBaseUrl,
|
|
2063
|
+
config.projectApiKey
|
|
2064
|
+
);
|
|
2065
|
+
const userRes = await api.get(`/auth/onboarding/${userId}`);
|
|
2066
|
+
if (!userRes.data?.ok) {
|
|
2067
|
+
throw new Error("Failed to fetch user details");
|
|
2068
|
+
}
|
|
2069
|
+
const refreshRes = await api.post("/auth/refresh");
|
|
2070
|
+
if (!refreshRes.data?.ok) {
|
|
2071
|
+
throw new Error("Failed to refresh session");
|
|
2072
|
+
}
|
|
2073
|
+
const userData = refreshRes.data.data.user;
|
|
2074
|
+
const accessToken = refreshRes.data.data.accessToken;
|
|
2075
|
+
setAccessToken(accessToken);
|
|
2076
|
+
const volrUser = toVolrUser(userData);
|
|
2077
|
+
setUser(volrUser);
|
|
2078
|
+
setLocalUser(volrUser);
|
|
2079
|
+
setIsLoading(false);
|
|
2080
|
+
options.onSuccess?.(volrUser);
|
|
2081
|
+
} catch (err) {
|
|
2082
|
+
console.error("Callback error:", err);
|
|
2083
|
+
const errorMsg = err.message || "Failed to complete authentication";
|
|
2084
|
+
setError(errorMsg);
|
|
2085
|
+
setIsLoading(false);
|
|
2086
|
+
options.onError?.(errorMsg);
|
|
2087
|
+
}
|
|
2088
|
+
};
|
|
2089
|
+
handleCallback();
|
|
2090
|
+
}, [config.apiBaseUrl, config.projectApiKey, refreshAccessToken, setAccessToken, setUser, toVolrUser]);
|
|
2091
|
+
return {
|
|
2092
|
+
isLoading,
|
|
2093
|
+
error,
|
|
2094
|
+
isNewUser,
|
|
2095
|
+
user
|
|
2096
|
+
};
|
|
2097
|
+
}
|
|
2014
2098
|
async function jsonRpc(rpcUrl, method, params) {
|
|
2015
2099
|
const payload = {
|
|
2016
2100
|
jsonrpc: "2.0",
|
|
@@ -2605,6 +2689,7 @@ exports.usePasskeyEnrollment = usePasskeyEnrollment;
|
|
|
2605
2689
|
exports.usePrecheck = usePrecheck;
|
|
2606
2690
|
exports.useRelay = useRelay;
|
|
2607
2691
|
exports.useVolr = useVolr;
|
|
2692
|
+
exports.useVolrAuthCallback = useVolrAuthCallback;
|
|
2608
2693
|
exports.useVolrLogin = useVolrLogin;
|
|
2609
2694
|
exports.useVolrWallet = useVolrWallet;
|
|
2610
2695
|
//# sourceMappingURL=index.cjs.map
|