@turnkey/sdk-react 2.0.0 → 2.0.1
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/CHANGELOG.md +6 -0
- package/README.md +222 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1 +1,223 @@
|
|
|
1
1
|
# @turnkey/sdk-react
|
|
2
|
+
|
|
3
|
+
The `@turnkey/sdk-react` package simplifies the integration of the Turnkey API into React-based applications. It builds on top of the `@turnkey/sdk-browser` package, enabling developers to implement authentication and wallet functionalities using React components.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
- **Authentication**: Supports email, passkey, phone, and social logins.
|
|
8
|
+
- **Wallet Operations**: Import and export wallets securely.
|
|
9
|
+
- **Client Utilities**: Includes `passkeyClient`, `authIframeClient`, and more.
|
|
10
|
+
- **Components**: Abstracts auth, session, import and export logic away from the developer and provides simple, easy to use plug-and-play components
|
|
11
|
+
- **Customization**: Theming options for your components to align with your application's design
|
|
12
|
+
|
|
13
|
+
Use `@turnkey/sdk-react` when building Next/React applications that interact with the Turnkey API.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
Install the package using npm or Yarn:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @turnkey/sdk-react
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Initialization
|
|
24
|
+
|
|
25
|
+
Set up the `TurnkeyProvider` in your application entry point (e.g., `App.tsx`):
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
import { TurnkeyProvider } from "@turnkey/sdk-react";
|
|
29
|
+
|
|
30
|
+
const turnkeyConfig = {
|
|
31
|
+
apiBaseUrl: "https://api.turnkey.com",
|
|
32
|
+
defaultOrganizationId: process.env.TURNKEY_ORGANIZATION_ID,
|
|
33
|
+
rpId: process.env.RPID, // Your application's domain for WebAuthn flows
|
|
34
|
+
iframeUrl: "https://auth.turnkey.com",
|
|
35
|
+
serverSignUrl: "http://localhost:3000/api", // Backend endpoint for signing operations (optional)
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
function App() {
|
|
39
|
+
return (
|
|
40
|
+
<TurnkeyProvider config={turnkeyConfig}>
|
|
41
|
+
{/* Rest of the app */}
|
|
42
|
+
</TurnkeyProvider>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default App;
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Using the React SDK
|
|
50
|
+
|
|
51
|
+
In components nested under the `TurnkeyProvider`, you can access Turnkey utilities using the `useTurnkey` hook:
|
|
52
|
+
|
|
53
|
+
```tsx
|
|
54
|
+
import { useTurnkey } from "@turnkey/sdk-react";
|
|
55
|
+
|
|
56
|
+
function ExampleComponent() {
|
|
57
|
+
const { turnkey, passkeyClient, authIframeClient } = useTurnkey();
|
|
58
|
+
|
|
59
|
+
const loginWithPasskey = async () => {
|
|
60
|
+
// Creates a read only session with passkey
|
|
61
|
+
await passkeyClient?.login();
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const initEmailAuth = async () => {
|
|
65
|
+
await turnkey?.serverSign("emailAuth", [
|
|
66
|
+
{
|
|
67
|
+
email: "<target user email>",
|
|
68
|
+
targetPublicKey: authIframeClient.iframePublicKey,
|
|
69
|
+
organizationId: "<target user suborg-id>",
|
|
70
|
+
},
|
|
71
|
+
]);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const loginWithIframe = async (credentialBundle: string) => {
|
|
75
|
+
await authIframeClient?.loginWithAuthBundle(credentialBundle); // Creates a read write session using a credential bundle returned from OTP Auth, Oauth, or Create Read Write session activities
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<div>
|
|
80
|
+
<button onClick={loginWithPasskey}>Login with Passkey</button>
|
|
81
|
+
<button onClick={() => initEmailAuth()}>Initialize Email Auth</button>
|
|
82
|
+
</div>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export default ExampleComponent;
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Components
|
|
90
|
+
|
|
91
|
+
All components require **Next.js 13+** with the [/app directory structure](https://nextjs.org/docs/app) to leverage server actions. Before using components be sure to Import Turnkey's default styles in your `layout.tsx` or equivalent entry point:
|
|
92
|
+
|
|
93
|
+
```tsx
|
|
94
|
+
import "@turnkey/sdk-react/styles";
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Authentication
|
|
98
|
+
|
|
99
|
+
The `Auth` component provides a complete authentication solution with support for various login methods.
|
|
100
|
+
|
|
101
|
+
#### Example
|
|
102
|
+
|
|
103
|
+
```tsx
|
|
104
|
+
import { Auth } from "@turnkey/sdk-react";
|
|
105
|
+
import { toast } from "sonner";
|
|
106
|
+
|
|
107
|
+
function AuthPage() {
|
|
108
|
+
const handleAuthSuccess = () => {
|
|
109
|
+
console.log("Auth successful!");
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const handleAuthError = (errorMessage: string) => {
|
|
113
|
+
toast.error(errorMessage);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const authConfig = {
|
|
117
|
+
emailEnabled: true,
|
|
118
|
+
passkeyEnabled: true,
|
|
119
|
+
phoneEnabled: false,
|
|
120
|
+
googleEnabled: true,
|
|
121
|
+
appleEnabled: false,
|
|
122
|
+
facebookEnabled: false,
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const configOrder = ["socials", "email", "phone", "passkey"];
|
|
126
|
+
|
|
127
|
+
return (
|
|
128
|
+
<Auth
|
|
129
|
+
authConfig={authConfig}
|
|
130
|
+
configOrder={configOrder}
|
|
131
|
+
onAuthSuccess={handleAuthSuccess}
|
|
132
|
+
onError={handleAuthError}
|
|
133
|
+
/>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export default AuthPage;
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Wallet Import and Export
|
|
141
|
+
|
|
142
|
+
#### Import Wallet Example
|
|
143
|
+
|
|
144
|
+
```tsx
|
|
145
|
+
import { Import } from "@turnkey/sdk-react";
|
|
146
|
+
import { toast } from "sonner";
|
|
147
|
+
|
|
148
|
+
function ImportWallet() {
|
|
149
|
+
const handleImportSuccess = () => {
|
|
150
|
+
toast.success("Wallet successfully imported!");
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const handleImportError = (errorMessage: string) => {
|
|
154
|
+
toast.error(errorMessage);
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
return (
|
|
158
|
+
<Import
|
|
159
|
+
onHandleImportSuccess={handleImportSuccess}
|
|
160
|
+
onError={handleImportError}
|
|
161
|
+
/>
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export default ImportWallet;
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
#### Export Wallet Example
|
|
169
|
+
|
|
170
|
+
```tsx
|
|
171
|
+
import { Export } from "@turnkey/sdk-react";
|
|
172
|
+
import { toast } from "sonner";
|
|
173
|
+
|
|
174
|
+
function ExportWallet() {
|
|
175
|
+
const walletId = "your-wallet-id";
|
|
176
|
+
|
|
177
|
+
const handleExportSuccess = () => {
|
|
178
|
+
toast.success("Wallet successfully exported!");
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const handleExportError = (errorMessage: string) => {
|
|
182
|
+
toast.error(errorMessage);
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
return (
|
|
186
|
+
<Export
|
|
187
|
+
walletId={walletId}
|
|
188
|
+
onHandleExportSuccess={handleExportSuccess}
|
|
189
|
+
onError={handleExportError}
|
|
190
|
+
/>
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export default ExportWallet;
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Theming with `TurnkeyThemeProvider`
|
|
198
|
+
|
|
199
|
+
Customize Turnkey components using CSS variables with the `TurnkeyThemeProvider`.
|
|
200
|
+
|
|
201
|
+
#### Example
|
|
202
|
+
|
|
203
|
+
```tsx
|
|
204
|
+
import { TurnkeyThemeProvider } from "@turnkey/sdk-react";
|
|
205
|
+
|
|
206
|
+
const customTheme = {
|
|
207
|
+
"--text-primary": "#333333",
|
|
208
|
+
"--button-bg": "#4c48ff",
|
|
209
|
+
"--button-hover-bg": "#3b38e6",
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
export default function App() {
|
|
213
|
+
return (
|
|
214
|
+
<TurnkeyThemeProvider theme={customTheme}>
|
|
215
|
+
<YourComponent />
|
|
216
|
+
</TurnkeyThemeProvider>
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## Code Examples
|
|
222
|
+
|
|
223
|
+
For detailed examples and advanced use cases, refer to our documentation [here](https://docs.turnkey.com/)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turnkey/sdk-react",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"exports": {
|
|
@@ -55,9 +55,9 @@
|
|
|
55
55
|
"next": "^15.0.2",
|
|
56
56
|
"react-apple-login": "^1.1.6",
|
|
57
57
|
"react-international-phone": "^4.3.0",
|
|
58
|
-
"@turnkey/crypto": "2.3.0",
|
|
59
|
-
"@turnkey/wallet-stamper": "1.0.2",
|
|
60
58
|
"@turnkey/sdk-browser": "1.11.0",
|
|
59
|
+
"@turnkey/wallet-stamper": "1.0.2",
|
|
60
|
+
"@turnkey/crypto": "2.3.0",
|
|
61
61
|
"@turnkey/sdk-server": "1.7.1"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|