@privy-io/react-auth 1.91.0 → 1.92.0

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.
@@ -1,322 +0,0 @@
1
- import { TransactionResponse } from '@ethersproject/providers';
2
- import { aH as PrivyErrorCode, U as User, L as LoginMethod, aI as LinkedAccountWithMetadata, O as OAuthTokens, f as BaseConnectedWallet, s as Wallet, w as MfaMethod, aJ as UserRecoveryMethod, D as SolanaTransactionReceipt, C as Chain, aK as FundingMethod, a5 as SolanaCluster, aE as ConnectedSolanaWallet } from './types.js';
3
-
4
- /**
5
- * `CallbackError` optionally includes a second parameter with further error details.
6
- */
7
- type CallbackError<Details extends Record<string, any> | undefined = undefined> = Details extends Record<string, any> ? (error: PrivyErrorCode, details: Details) => void : (error: PrivyErrorCode) => void;
8
- interface PrivyEvents {
9
- login: {
10
- /**
11
- * Callback that will execute once a `login` flow successfully completes.
12
- * - If `config.embeddedWallets.createOnLogin` is set to 'off' or a wallet creation flow is not applicable,
13
- * this will run after the user successfully authenticates.
14
- * - If `config.embeddedWallets.createOnLogin` is set to 'users-without-wallets' or 'all-users',
15
- * this will run after the user successfully authenticates _and_ creates their wallet (if applicable).
16
- * - If a user is already authenticated, this will run immediately and the `wasAlreadyAuthenticated` flag will be set to `true`.
17
- *
18
- * @param user {@link User} the `user` oject corresponding to the authenticated user
19
- * @param isNewUser {boolean} boolean flag indicating if this is the user's first time logging in to your app
20
- * @param wasAlreadyAuthenticated {boolean} - boolean flag indicating whether the user entered the application already authenticated
21
- * @param loginMethod {string} - the method used by the user to login
22
- * @param loginAccount - the account corresponding to the loginMethod used
23
- */
24
- onComplete?: (user: User, isNewUser: boolean, wasAlreadyAuthenticated: boolean, loginMethod: LoginMethod | null, loginAccount: LinkedAccountWithMetadata | null) => void;
25
- /**
26
- * @experimental
27
- *
28
- * Callback that will execute once a successful OAuth login flow completes.
29
- * This will only run in the case of an OAuth login flow.
30
- *
31
- * This will always be called before `onComplete` in the case of an OAuth login flow.
32
- * If you will be doing anything after the user is logged in (e.g. sending data to your API or redirecting to an authenticated route), you should wait for `onComplete` to run.
33
- *
34
- * @param oAuthTokens {@link OAuthTokens} - the OAuth tokens returned from the OAuth provider
35
- */
36
- onOAuthLoginComplete?: (oAuthTokens: OAuthTokens) => void;
37
- /**
38
- * Callback that will execute in the case of a non-successful login.
39
- *
40
- * @param error {@link PrivyErrorCode} - the corresponding error code
41
- *
42
- */
43
- onError?: CallbackError;
44
- };
45
- logout: {
46
- /**
47
- * Callback that will execute when a user successfully logs out.
48
- */
49
- onSuccess?: () => void;
50
- };
51
- connectWallet: {
52
- /**
53
- * Callback that will execute once a successful `connectWallet` completes.
54
- * This will not run in the case of a wallet-based authentication or link flow.
55
- *
56
- * @param wallet {@link BaseConnectedWallet} the `wallet` object correspending to the connection
57
- */
58
- onSuccess?: (wallet: BaseConnectedWallet) => void;
59
- /**
60
- * Callback that will execute in the case of a non-successful wallet connection.
61
- *
62
- * @param error {@link PrivyErrorCode} - the corresponding error code
63
- */
64
- onError?: CallbackError;
65
- };
66
- createWallet: {
67
- /**
68
- * Callback that will execute once on a successful embedded wallet creation.
69
- * This will run when `createWallet` is called manually, or when `config.embeddedWallets.createOnLogin` triggers
70
- * an automatic wallet creation.
71
- *
72
- * @param wallet {@link BaseConnectedWallet}- the created `wallet` object
73
- *
74
- */
75
- onSuccess?: (wallet: Wallet) => void;
76
- /**
77
- * Callback that will execute in the case of a non-successful wallet creation.
78
- *
79
- * @param error {@link PrivyErrorCode} - the corresponding error code
80
- *
81
- */
82
- onError?: CallbackError;
83
- };
84
- linkAccount: {
85
- /**
86
- * Callback that will execute once on a successful linking of a new account/login method.
87
- * This will run when any of the 'link' methods are called manually.
88
- * @param user {@link User}- the user the account was linked to
89
- * @param linkMethod {@link LoginMethod}- the type of linked account
90
- * @param linkedAccount - the newly linked account
91
- */
92
- onSuccess?: (user: User, linkMethod: LoginMethod, linkedAccount: LinkedAccountWithMetadata) => void;
93
- /**
94
- * Callback that will execute in the case of a non-successful account linking.
95
- *
96
- * @param error {PrivyErrorCode} - the corresponding error code
97
- * @param details.linkMethod {LoginMethod} - the type of (attempted) linked account
98
- *
99
- */
100
- onError?: CallbackError<{
101
- linkMethod: LoginMethod;
102
- }>;
103
- };
104
- update: {
105
- /**
106
- * Callback that will execute once on a successful updating of an account.
107
- * This will run when any of the 'updateAccount' methods are called manually.
108
- * @param user {@link User}- the user the account was linked to
109
- * @param updateMethod {@link LoginMethod}- the type of updated account
110
- * @param updatedAccount - the newly updated account
111
- */
112
- onSuccess?: (user: User, updateMethod: LoginMethod, updatedAccount: LinkedAccountWithMetadata) => void;
113
- /**
114
- * Callback that will execute in the case of a non-successful account linking.
115
- *
116
- * @param error {PrivyErrorCode} - the corresponding error code
117
- * @param details.linkMethod {LoginMethod} - the type of (attempted) linked account
118
- *
119
- */
120
- onError?: CallbackError<{
121
- linkMethod: LoginMethod;
122
- }>;
123
- };
124
- configureMfa: {
125
- /**
126
- * Callback that will execute when MFA is required to complete a given action.
127
- * @param mfaMethods {@link MfaMethod[]} - List of MFA methods that the user can choose from
128
- */
129
- onMfaRequired: (mfaMethods: MfaMethod[]) => void;
130
- };
131
- setWalletPassword: {
132
- /**
133
- * Callback that will execute once a successful `setWalletPassword` completes.
134
- * @param wallet {@link Wallet}- the `wallet` object that the password was set for
135
- */
136
- onSuccess?: (wallet: Wallet) => void;
137
- /**
138
- * Callback that will execute in the case of a non-successful setWalletPassword.
139
- *
140
- * @param error {PrivyErrorCode} - the corresponding error code
141
- */
142
- onError?: CallbackError;
143
- };
144
- setWalletRecovery: {
145
- /**
146
- * Callback that will execute once a successful `setWalletRecovery` completes.
147
- * @param wallet {@link Wallet}- the `walle]et` object that the recovery was set for
148
- */
149
- onSuccess?: (method: UserRecoveryMethod, wallet: Wallet) => void;
150
- /**
151
- * Callback that will execute in the case of a non-successful setWalletRecovery.
152
- *
153
- * @param error {PrivyErrorCode} - the corresponding error code
154
- */
155
- onError?: CallbackError;
156
- };
157
- signMessage: {
158
- /**
159
- * Callback that will execute once a successful `signMessage` completes.
160
- * This will not run in the case of a wallet-based authentication or link flow.
161
- * @param signature - the signature (type string) of the embedded wallet used to sign message
162
- */
163
- onSuccess?: (signature: string) => void;
164
- /**
165
- * Callback that will execute in the case of a non-successful signMessage.
166
- *
167
- * @param error {@link PrivyErrorCode} - the corresponding error code
168
- * */
169
- onError?: CallbackError;
170
- };
171
- signTypedData: {
172
- /**
173
- * Callback that will execute once a successful `signTypedData` completes.
174
- * @param signature - the signature (type string) of the embedded wallet used to sign
175
- */
176
- onSuccess?: (signature: string) => void;
177
- /**
178
- * Callback that will execute in the case of a non-successful signTypedData.
179
- *
180
- * @param error {@link PrivyErrorCode} - the corresponding error code
181
- * */
182
- onError?: CallbackError;
183
- };
184
- sendTransaction: {
185
- /**
186
- * Callback that will execute once a successful `sendTransaction` completes.
187
- * This will not run in the case of a wallet-based authentication or link flow.
188
- * @param response - the response (type TransactionResponse https://docs.ethers.org/v5/api/providers/types/#providers-TransactionResponse) from the successful transaction
189
- */
190
- onSuccess?: (response: TransactionResponse) => void;
191
- /**
192
- * Callback that will execute in the case of a non-successful sendTransaction.
193
- *
194
- * @param error {@link PrivyErrorCode} - the corresponding error code
195
- * */
196
- onError?: CallbackError;
197
- };
198
- sendSolanaTransaction: {
199
- /**
200
- * Callback that will execute once a successful `sendSolanaTransaction` completes.
201
- * This will not run in the case of a wallet-based authentication or link flow.
202
- * @param response - the response {@link https://solana-labs.github.io/solana-web3.js/types/ParsedTransactionMeta.html SolanaTransactionReceipt} from the successful transaction
203
- */
204
- onSuccess?: (response: SolanaTransactionReceipt) => void;
205
- /**
206
- * Callback that will execute in the case of a non-successful sendTransaction.
207
- *
208
- * @param error {@link PrivyErrorCode} - the corresponding error code
209
- * */
210
- onError?: CallbackError;
211
- };
212
- accessToken: {
213
- /**
214
- * Callback that will execute when a user's access token is granted.
215
- * @param accessToken - The user's access token
216
- */
217
- onAccessTokenGranted: (accessToken: string) => void;
218
- /**
219
- * Callback that will execute when a user's access token is removed.
220
- */
221
- onAccessTokenRemoved: () => void;
222
- };
223
- oAuthAuthorization: {
224
- /**
225
- * Callback that will execute when a user successfully authorizes an OAuth flow.
226
- *
227
- * @param oAuthTokens {@link OAuthTokens} - the OAuth tokens returned from the OAuth provider:
228
- * @param oAuthTokens.provider - {string} The OAuth provider type.
229
- * @param oAuthTokens.accessToken - {string} The OAuth access token.
230
- * @param oAuthTokens.accessTokenExpiresInSeconds - {number} (optional) The number of seconds until the OAuth access token expires.
231
- * @param oAuthTokens.refreshToken - {string} (optional) The OAuth refresh token.
232
- * @param oAuthTokens.refreshTokenExpiresInSeconds - {number} (optional) The number of seconds until the OAuth refresh token expires.
233
- * if the refresh token is present and this field is undefined, it is assumed
234
- * that the refresh token does not have an expiration date.
235
- * @param oAuthTokens.scopes - {string[]} (optional) The list of OAuth scopes the access token is approved for.
236
- *
237
- * @param o.user {@link User} (optional) The list of OAuth scopes the access token is approved for.
238
- */
239
- onOAuthTokenGrant: (oAuthTokens: OAuthTokens, o: {
240
- user: User;
241
- }) => void;
242
- };
243
- fundWallet: {
244
- /**
245
- * Callback that will execute when a funding flow is exited. This fires when a user closes a funding flow modal, for any reason.
246
- *
247
- * @param fundingMethod {@link FundingMethod} The funding method associated with the flow at time of exit. If the user had not yet selected
248
- * @param balance {@link BigNumber} The value for the funded wallet at the point of user exit.
249
- * a recovery method, this will be null.
250
- */
251
- onUserExited?: (o: {
252
- address: string;
253
- chain: Chain;
254
- fundingMethod: FundingMethod | 'manual' | null;
255
- balance: bigint | undefined;
256
- }) => void;
257
- };
258
- fundSolanaWallet: {
259
- /**
260
- * Callback that will execute when a funding flow is exited. This fires when a user closes a funding flow modal, for any reason.
261
- *
262
- * @param fundingMethod {@link FundingMethod} The funding method associated with the flow at time of exit. If the user had not yet selected
263
- * @param balance {@link BigNumber} The value for the funded wallet at the point of user exit.
264
- * a recovery method, this will be null.
265
- */
266
- onUserExited?: (o: {
267
- address: string;
268
- cluster: SolanaCluster;
269
- fundingMethod: FundingMethod | 'manual' | null;
270
- balance: bigint | undefined;
271
- }) => void;
272
- };
273
- customAuth: {
274
- /**
275
- * Callback that will execute when Privy successfully exchanges a custom auth JWT for a Privy JWT
276
- * @param o.user - The Privy user
277
- */
278
- onAuthenticated: (o: {
279
- user: User;
280
- }) => void;
281
- /**
282
- * Callback that will execute when Privy detects a user is logged out from the third-party auth system, and correspondingly logs the user out.
283
- */
284
- onUnauthenticated: () => void;
285
- };
286
- }
287
-
288
- /**
289
- * Hook to create and interact with Solana wallets. This currently only supports an embedded Solana wallet and no
290
- * external wallets.
291
- *
292
- * @returns wallets {ConnectedSolanaWallet[]} an array of connected Solana wallets
293
- * @returns createWallet {() => Promise<Wallet>} an method to create an embedded Solana wallet.
294
- */
295
- interface UseSolanaWalletsInterface {
296
- /**
297
- * An array of the connected Solana wallets for the user. Currently, this will only contain the embedded
298
- * Solana wallet if the user has created one.
299
- */
300
- wallets: ConnectedSolanaWallet[];
301
- /**
302
- * Method to create an embedded Solana wallet for a user. This method will throw an error if the user already has an
303
- * embedded Solana or Ethereum wallet. Currently, only embedded Solana wallets with automatic recovery are supported.
304
- * @returns wallet {Wallet} the Solana linked account for the user.
305
- */
306
- createWallet: () => Promise<Wallet>;
307
- /**
308
- * Shows the user a Privy modal, from which they can copy their embedded solana wallet's private
309
- * key for easy export to another wallet client (e.g. Phantom, Backpack). The private key is loaded
310
- * on an iframe running on a separate domain from your app, meaning your app cannot access it.
311
- *
312
- * This method will error if the user is not authenticated or does not have an embedded solana wallet.
313
- * @param options {@link {address: string}} (optional) wallet address to export the private key for
314
- * @returns Promise that resolves once the user exits the modal
315
- */
316
- exportWallet: (options?: {
317
- address: string;
318
- }) => Promise<void>;
319
- }
320
- declare const useSolanaWallets: () => UseSolanaWalletsInterface;
321
-
322
- export { type CallbackError as C, type PrivyEvents as P, type UseSolanaWalletsInterface as U, useSolanaWallets as u };