@b3dotfun/sdk 0.0.82-alpha.3 → 0.0.83-test.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.
Files changed (53) hide show
  1. package/dist/cjs/anyspend/react/components/AnySpend.js +3 -0
  2. package/dist/cjs/anyspend/react/components/AnySpendCustom.js +3 -0
  3. package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethod.js +177 -47
  4. package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +3 -0
  5. package/dist/cjs/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.d.ts +10 -0
  6. package/dist/cjs/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.js +73 -0
  7. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +57 -12
  8. package/dist/cjs/global-account/react/hooks/index.d.ts +1 -0
  9. package/dist/cjs/global-account/react/hooks/index.js +3 -1
  10. package/dist/cjs/global-account/react/hooks/useAuth.d.ts +76 -0
  11. package/dist/cjs/global-account/react/hooks/useAuth.js +338 -0
  12. package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +2 -2
  13. package/dist/cjs/global-account/react/hooks/useAuthentication.js +72 -63
  14. package/dist/cjs/global-account/react/hooks/useTWAuth.d.ts +3 -0
  15. package/dist/cjs/global-account/react/hooks/useTWAuth.js +8 -0
  16. package/dist/cjs/global-account/react/hooks/useTurnkeyAuth.js +54 -24
  17. package/dist/cjs/global-account/react/hooks/useUserQuery.d.ts +1 -1
  18. package/dist/esm/anyspend/react/components/AnySpend.js +3 -0
  19. package/dist/esm/anyspend/react/components/AnySpendCustom.js +3 -0
  20. package/dist/esm/anyspend/react/components/common/CryptoPaymentMethod.js +175 -45
  21. package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +3 -0
  22. package/dist/esm/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.d.ts +10 -0
  23. package/dist/esm/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.js +70 -0
  24. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +57 -12
  25. package/dist/esm/global-account/react/hooks/index.d.ts +1 -0
  26. package/dist/esm/global-account/react/hooks/index.js +1 -0
  27. package/dist/esm/global-account/react/hooks/useAuth.d.ts +76 -0
  28. package/dist/esm/global-account/react/hooks/useAuth.js +332 -0
  29. package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +2 -2
  30. package/dist/esm/global-account/react/hooks/useAuthentication.js +72 -63
  31. package/dist/esm/global-account/react/hooks/useTWAuth.d.ts +3 -0
  32. package/dist/esm/global-account/react/hooks/useTWAuth.js +8 -0
  33. package/dist/esm/global-account/react/hooks/useTurnkeyAuth.js +54 -24
  34. package/dist/esm/global-account/react/hooks/useUserQuery.d.ts +1 -1
  35. package/dist/styles/index.css +1 -1
  36. package/dist/types/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.d.ts +10 -0
  37. package/dist/types/global-account/react/hooks/index.d.ts +1 -0
  38. package/dist/types/global-account/react/hooks/useAuth.d.ts +76 -0
  39. package/dist/types/global-account/react/hooks/useAuthentication.d.ts +2 -2
  40. package/dist/types/global-account/react/hooks/useTWAuth.d.ts +3 -0
  41. package/dist/types/global-account/react/hooks/useUserQuery.d.ts +1 -1
  42. package/package.json +1 -1
  43. package/src/anyspend/react/components/AnySpend.tsx +4 -0
  44. package/src/anyspend/react/components/AnySpendCustom.tsx +4 -0
  45. package/src/anyspend/react/components/common/CryptoPaymentMethod.tsx +253 -22
  46. package/src/anyspend/react/hooks/useAnyspendFlow.ts +4 -0
  47. package/src/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.ts +80 -0
  48. package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +77 -22
  49. package/src/global-account/react/hooks/index.ts +1 -0
  50. package/src/global-account/react/hooks/useAuth.ts +380 -0
  51. package/src/global-account/react/hooks/useAuthentication.ts +88 -85
  52. package/src/global-account/react/hooks/useTWAuth.tsx +10 -0
  53. package/src/global-account/react/hooks/useTurnkeyAuth.ts +59 -26
@@ -0,0 +1,76 @@
1
+ import { Wallet } from "thirdweb/wallets";
2
+ import { preAuthenticate } from "thirdweb/wallets/in-app";
3
+ /**
4
+ * Unified authentication hook that uses Turnkey for authentication
5
+ * This replaces the previous Thirdweb-based authentication
6
+ *
7
+ * This hook provides 1:1 feature parity with useAuthentication.ts
8
+ */
9
+ export declare function useAuth(): {
10
+ authenticate: (turnkeySessionJwt: string, partnerId: string) => Promise<import("@feathersjs/authentication").AuthenticationResult>;
11
+ reAuthenticate: () => Promise<import("@feathersjs/authentication").AuthenticationResult>;
12
+ logout: (callback?: () => void) => Promise<void>;
13
+ isAuthenticated: boolean;
14
+ isReady: boolean;
15
+ isConnecting: boolean;
16
+ isConnected: boolean;
17
+ wallet: import("thirdweb/dist/types/wallets/in-app/core/wallet/types").EcosystemWallet;
18
+ preAuthenticate: typeof preAuthenticate;
19
+ connect: (_walleAutoConnectedWith: Wallet, allConnectedWallets: Wallet[]) => Promise<void>;
20
+ isAuthenticating: boolean;
21
+ onConnect: (_walleAutoConnectedWith: Wallet, allConnectedWallets: Wallet[]) => Promise<void>;
22
+ user: {
23
+ email?: string | undefined;
24
+ telNumber?: string | undefined;
25
+ username?: string | undefined;
26
+ ens?: string | undefined;
27
+ avatar?: string | undefined;
28
+ preferences?: {} | undefined;
29
+ referredBy?: string | {} | undefined;
30
+ sourceApp?: string | undefined;
31
+ referralCode?: string | undefined;
32
+ userGroups?: number[] | undefined;
33
+ isMigratedFromBSMNT?: boolean | undefined;
34
+ privyLinkedAccounts?: {
35
+ name?: string | undefined;
36
+ address?: string | undefined;
37
+ email?: string | undefined;
38
+ chain_type?: string | undefined;
39
+ lv?: number | undefined;
40
+ wallet_client_type?: string | undefined;
41
+ smart_wallet_type?: string | undefined;
42
+ subject?: string | undefined;
43
+ type: string;
44
+ }[] | undefined;
45
+ twProfiles?: {
46
+ type: string;
47
+ details: {
48
+ id?: string | undefined;
49
+ name?: string | undefined;
50
+ address?: string | undefined;
51
+ email?: string | undefined;
52
+ phone?: string | undefined;
53
+ username?: string | undefined;
54
+ fid?: string | undefined;
55
+ };
56
+ }[] | undefined;
57
+ turnkeySubOrgs?: {
58
+ hasDelegatedUser?: boolean | undefined;
59
+ subOrgId: string;
60
+ accounts: Record<string, any>[];
61
+ }[] | undefined;
62
+ _id: string | {};
63
+ userId: string;
64
+ smartAccountAddress: string;
65
+ createdAt: number;
66
+ updatedAt: number;
67
+ partnerIds: {
68
+ privyId?: string | undefined;
69
+ thirdwebId?: string | undefined;
70
+ turnkeyId?: string | undefined;
71
+ turnkeyOtpId?: string | undefined;
72
+ };
73
+ } | undefined;
74
+ refetchUser: () => Promise<import("@feathersjs/authentication").AuthenticationResult>;
75
+ setUser: (newUser?: import("@b3dotfun/b3-api").Users) => void;
76
+ };
@@ -0,0 +1,338 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.useAuth = useAuth;
7
+ const app_1 = __importDefault(require("../../../global-account/app"));
8
+ const bsmnt_1 = require("../../../global-account/bsmnt");
9
+ const react_1 = require("../../../global-account/react");
10
+ const constants_1 = require("../../../shared/constants");
11
+ const debug_1 = require("../../../shared/utils/debug");
12
+ const thirdweb_1 = require("../../../shared/utils/thirdweb");
13
+ const core_1 = require("@wagmi/core");
14
+ const react_2 = require("react");
15
+ const react_3 = require("thirdweb/react");
16
+ const wallets_1 = require("thirdweb/wallets");
17
+ const in_app_1 = require("thirdweb/wallets/in-app");
18
+ const wagmi_1 = require("wagmi");
19
+ const LocalSDKProvider_1 = require("../components/B3Provider/LocalSDKProvider");
20
+ const useB3_1 = require("../components/B3Provider/useB3");
21
+ const createWagmiConfig_1 = require("../utils/createWagmiConfig");
22
+ const useSearchParamsSSR_1 = require("./useSearchParamsSSR");
23
+ const useUserQuery_1 = require("./useUserQuery");
24
+ const debug = (0, debug_1.debugB3React)("useAuth");
25
+ /**
26
+ * Unified authentication hook that uses Turnkey for authentication
27
+ * This replaces the previous Thirdweb-based authentication
28
+ *
29
+ * This hook provides 1:1 feature parity with useAuthentication.ts
30
+ */
31
+ function useAuth() {
32
+ const { onConnectCallback } = (0, react_2.useContext)(LocalSDKProvider_1.LocalSDKContext);
33
+ const { disconnect } = (0, react_3.useDisconnect)();
34
+ const wallets = (0, react_3.useConnectedWallets)();
35
+ const activeWallet = (0, react_3.useActiveWallet)();
36
+ const isAuthenticated = (0, react_1.useAuthStore)(state => state.isAuthenticated);
37
+ const setIsAuthenticated = (0, react_1.useAuthStore)(state => state.setIsAuthenticated);
38
+ const setIsConnected = (0, react_1.useAuthStore)(state => state.setIsConnected);
39
+ const isConnecting = (0, react_1.useAuthStore)(state => state.isConnecting);
40
+ const isConnected = (0, react_1.useAuthStore)(state => state.isConnected);
41
+ const isAuthenticating = (0, react_1.useAuthStore)(state => state.isAuthenticating);
42
+ const setIsAuthenticating = (0, react_1.useAuthStore)(state => state.setIsAuthenticating);
43
+ const setHasStartedConnecting = (0, react_1.useAuthStore)(state => state.setHasStartedConnecting);
44
+ const setActiveWallet = (0, react_3.useSetActiveWallet)();
45
+ const hasStartedConnecting = (0, react_1.useAuthStore)(state => state.hasStartedConnecting);
46
+ const useAutoConnectLoadingPrevious = (0, react_2.useRef)(false);
47
+ const referralCode = (0, useSearchParamsSSR_1.useSearchParam)("referralCode");
48
+ const { partnerId } = (0, useB3_1.useB3)();
49
+ const wagmiConfig = (0, createWagmiConfig_1.createWagmiConfig)({ partnerId });
50
+ const { connect } = (0, wagmi_1.useConnect)();
51
+ const activeWagmiAccount = (0, wagmi_1.useAccount)();
52
+ const { switchAccount } = (0, wagmi_1.useSwitchAccount)();
53
+ const { user, setUser } = (0, useUserQuery_1.useUserQuery)();
54
+ debug("@@activeWagmiAccount", activeWagmiAccount);
55
+ const wallet = (0, wallets_1.ecosystemWallet)(constants_1.ecosystemWalletId, {
56
+ partnerId: partnerId,
57
+ });
58
+ /**
59
+ * Re-authenticate using existing session
60
+ * Also updates user state and authenticates with BSMNT
61
+ */
62
+ const reAuthenticate = (0, react_2.useCallback)(async () => {
63
+ debug("Re-authenticating...");
64
+ try {
65
+ const response = await app_1.default.reAuthenticate();
66
+ debug("Re-authentication successful", response);
67
+ // Update user state if user data exists
68
+ if (response.user) {
69
+ setUser(response.user);
70
+ debug("User state updated", response.user);
71
+ }
72
+ // Authenticate with BSMNT
73
+ try {
74
+ const b3Jwt = await (0, bsmnt_1.authenticateWithB3JWT)(response.accessToken);
75
+ debug("BSMNT re-authentication successful", b3Jwt);
76
+ }
77
+ catch (bsmntError) {
78
+ // BSMNT authentication failure shouldn't block the main auth flow
79
+ debug("BSMNT re-authentication failed (non-critical)", bsmntError);
80
+ }
81
+ return response;
82
+ }
83
+ catch (err) {
84
+ debug("Re-authentication failed", err);
85
+ throw err;
86
+ }
87
+ }, [setUser]);
88
+ const syncWagmi = (0, react_2.useCallback)(async () => {
89
+ function syncWagmiFunc() {
90
+ const connectors = (0, core_1.getConnectors)(wagmiConfig);
91
+ debug("@@syncWagmi", {
92
+ connectors,
93
+ wallets,
94
+ });
95
+ // For each that matchs a TW wallet on wallets, connect to the wagmi connector
96
+ // or, since ecosystem wallets is separate, connect those via in-app-wallet from wagmi
97
+ connectors.forEach(async (connector) => {
98
+ const twWallet = wallets.find(wallet => wallet.id === connector.id || connector.id === "in-app-wallet");
99
+ // If no TW wallet, do not prompt the user to connect
100
+ if (!twWallet) {
101
+ return;
102
+ }
103
+ // Metamask will prompt to connect, we can just switch accounts here.
104
+ if (connector.id === "io.metamask") {
105
+ return switchAccount({ connector });
106
+ }
107
+ if (
108
+ // If it's not an in-app wallet or it is the ecosystem wallet, connect
109
+ connector.id !== "in-app-wallet" ||
110
+ (connector.id === "in-app-wallet" && twWallet.id === constants_1.ecosystemWalletId)) {
111
+ try {
112
+ const options = {
113
+ wallet: twWallet, // the connected wallet
114
+ };
115
+ debug("@@syncWagmi:connecting", { twWallet, connector });
116
+ connect({
117
+ connector,
118
+ ...options,
119
+ });
120
+ }
121
+ catch (error) {
122
+ console.error("@@syncWagmi:error", error);
123
+ }
124
+ }
125
+ else {
126
+ debug("@@syncWagmi:not-connecting", connector);
127
+ }
128
+ });
129
+ }
130
+ syncWagmiFunc();
131
+ // wagmi config shouldn't change
132
+ // eslint-disable-next-line react-hooks/exhaustive-deps
133
+ }, [partnerId, wallets]);
134
+ (0, react_2.useEffect)(() => {
135
+ syncWagmi();
136
+ }, [wallets, syncWagmi]);
137
+ /**
138
+ * Authenticate user using Turnkey
139
+ * Note: This no longer requires a wallet for authentication.
140
+ * Wallets are still used for signing transactions, but authentication is done via Turnkey email OTP.
141
+ *
142
+ * For backward compatibility, this function still accepts a wallet parameter,
143
+ * but it's not used for authentication anymore.
144
+ */
145
+ const authenticateUser = (0, react_2.useCallback)(async () => {
146
+ setHasStartedConnecting(true);
147
+ // Try to re-authenticate first
148
+ try {
149
+ const userAuth = await reAuthenticate();
150
+ setUser(userAuth.user);
151
+ setIsAuthenticated(true);
152
+ setIsAuthenticating(false);
153
+ debug("Re-authenticated successfully", { userAuth });
154
+ // Authenticate on BSMNT with B3 JWT
155
+ const b3Jwt = await (0, bsmnt_1.authenticateWithB3JWT)(userAuth.accessToken);
156
+ debug("@@b3Jwt", b3Jwt);
157
+ return userAuth;
158
+ }
159
+ catch (error) {
160
+ // If re-authentication fails, user needs to authenticate via Turnkey
161
+ // This should be handled by the Turnkey auth modal/flow
162
+ debug("Re-authentication failed. User needs to authenticate via Turnkey.", error);
163
+ setIsAuthenticated(false);
164
+ setIsAuthenticating(false);
165
+ throw new Error("Authentication required. Please authenticate via Turnkey.");
166
+ }
167
+ }, [reAuthenticate, setIsAuthenticated, setIsAuthenticating, setUser, setHasStartedConnecting]);
168
+ /**
169
+ * Authenticate with Turnkey using email OTP
170
+ * This is the primary authentication method, replacing Thirdweb wallet-based auth
171
+ *
172
+ * This function:
173
+ * 1. Authenticates with FeathersJS (persists session via cookies)
174
+ * 2. Sets user state in the user store (persists to localStorage)
175
+ * 3. Authenticates with BSMNT for basement integration
176
+ */
177
+ const authenticate = (0, react_2.useCallback)(async (turnkeySessionJwt, partnerId) => {
178
+ if (!turnkeySessionJwt) {
179
+ throw new Error("Turnkey session JWT is required");
180
+ }
181
+ debug("Authenticating with Turnkey JWT", { referralCode, partnerId });
182
+ try {
183
+ // Step 1: Authenticate with FeathersJS (session persisted via cookies)
184
+ const response = await app_1.default.authenticate({
185
+ strategy: "turnkey-jwt",
186
+ accessToken: turnkeySessionJwt,
187
+ referralCode,
188
+ partnerId: partnerId,
189
+ });
190
+ debug("Authentication successful", response);
191
+ // Step 2: Set user state (persists to localStorage via Zustand)
192
+ if (response.user) {
193
+ setUser(response.user);
194
+ debug("User state updated", response.user);
195
+ }
196
+ // Step 3: Authenticate with BSMNT for basement integration
197
+ try {
198
+ const b3Jwt = await (0, bsmnt_1.authenticateWithB3JWT)(response.accessToken);
199
+ debug("BSMNT authentication successful", b3Jwt);
200
+ }
201
+ catch (bsmntError) {
202
+ // BSMNT authentication failure shouldn't block the main auth flow
203
+ debug("BSMNT authentication failed (non-critical)", bsmntError);
204
+ }
205
+ return response;
206
+ }
207
+ catch (err) {
208
+ debug("Authentication failed", err);
209
+ throw err;
210
+ }
211
+ }, [referralCode, setUser]);
212
+ /**
213
+ * Handle wallet connection
214
+ * Note: With Turnkey migration, wallet connection is primarily for signing transactions,
215
+ * not for authentication. Authentication should be done separately via Turnkey email OTP.
216
+ */
217
+ /**
218
+ * Handle wallet connection
219
+ * Note: With Turnkey migration, wallet connection is primarily for signing transactions,
220
+ * not for authentication. Authentication should be done separately via Turnkey email OTP.
221
+ */
222
+ const onConnect = (0, react_2.useCallback)(async (_walleAutoConnectedWith, allConnectedWallets) => {
223
+ debug("@@useAuth:onConnect", { _walleAutoConnectedWith, allConnectedWallets });
224
+ const wallet = allConnectedWallets.find(wallet => wallet.id.startsWith("ecosystem."));
225
+ if (!wallet) {
226
+ throw new Error("No smart wallet found during auto-connect");
227
+ }
228
+ debug("@@useAuth:onConnect", { wallet });
229
+ try {
230
+ setHasStartedConnecting(true);
231
+ setIsConnected(true);
232
+ setIsAuthenticating(true);
233
+ await setActiveWallet(wallet);
234
+ // Try to authenticate user (will use re-authenticate if session exists)
235
+ // If no session exists, authentication will need to happen via Turnkey flow
236
+ try {
237
+ const userAuth = await authenticateUser();
238
+ if (userAuth && onConnectCallback) {
239
+ await onConnectCallback(wallet, userAuth.accessToken);
240
+ }
241
+ }
242
+ catch (authError) {
243
+ // Authentication failed - this is expected if user hasn't authenticated via Turnkey yet
244
+ // The Turnkey auth modal should handle this
245
+ debug("@@useAuth:onConnect:authFailed", { authError });
246
+ // Don't set isAuthenticated to false here - let the Turnkey flow handle it
247
+ }
248
+ }
249
+ catch (error) {
250
+ debug("@@useAuth:onConnect:failed", { error });
251
+ setIsAuthenticated(false);
252
+ setUser(undefined);
253
+ }
254
+ finally {
255
+ setIsAuthenticating(false);
256
+ }
257
+ debug({
258
+ isAuthenticated,
259
+ isAuthenticating,
260
+ isConnected,
261
+ });
262
+ }, [
263
+ onConnectCallback,
264
+ authenticateUser,
265
+ isAuthenticated,
266
+ isAuthenticating,
267
+ isConnected,
268
+ setActiveWallet,
269
+ setHasStartedConnecting,
270
+ setIsAuthenticated,
271
+ setIsAuthenticating,
272
+ setIsConnected,
273
+ setUser,
274
+ ]);
275
+ const logout = (0, react_2.useCallback)(async (callback) => {
276
+ if (activeWallet) {
277
+ debug("@@logout:activeWallet", activeWallet);
278
+ disconnect(activeWallet);
279
+ debug("@@logout:activeWallet", activeWallet);
280
+ }
281
+ // Log out of each wallet
282
+ wallets.forEach(wallet => {
283
+ console.log("@@logging out", wallet);
284
+ disconnect(wallet);
285
+ });
286
+ // Delete localStorage thirdweb:connected-wallet-ids
287
+ // https://npc-labs.slack.com/archives/C070E6HNG85/p1750185115273099
288
+ if (typeof localStorage !== "undefined") {
289
+ localStorage.removeItem("thirdweb:connected-wallet-ids");
290
+ localStorage.removeItem("wagmi.store");
291
+ localStorage.removeItem("lastAuthProvider");
292
+ localStorage.removeItem("b3-user");
293
+ }
294
+ app_1.default.logout();
295
+ debug("@@logout:loggedOut");
296
+ setIsAuthenticated(false);
297
+ setIsConnected(false);
298
+ setUser();
299
+ callback?.();
300
+ }, [activeWallet, disconnect, wallets, setIsAuthenticated, setUser, setIsConnected]);
301
+ const { isLoading: useAutoConnectLoading } = (0, react_3.useAutoConnect)({
302
+ client: thirdweb_1.client,
303
+ wallets: [wallet],
304
+ onConnect,
305
+ onTimeout: () => {
306
+ logout().catch(error => {
307
+ debug("@@useAuth:logout on timeout failed", { error });
308
+ });
309
+ },
310
+ });
311
+ /**
312
+ * useAutoConnectLoading starts as false
313
+ */
314
+ (0, react_2.useEffect)(() => {
315
+ if (!useAutoConnectLoading && useAutoConnectLoadingPrevious.current && !hasStartedConnecting) {
316
+ setIsAuthenticating(false);
317
+ }
318
+ useAutoConnectLoadingPrevious.current = useAutoConnectLoading;
319
+ }, [useAutoConnectLoading, hasStartedConnecting, setIsAuthenticating]);
320
+ const isReady = isAuthenticated && !isAuthenticating;
321
+ return {
322
+ authenticate,
323
+ reAuthenticate,
324
+ logout,
325
+ isAuthenticated,
326
+ isReady,
327
+ isConnecting,
328
+ isConnected,
329
+ wallet,
330
+ preAuthenticate: in_app_1.preAuthenticate,
331
+ connect: onConnect,
332
+ isAuthenticating,
333
+ onConnect,
334
+ user,
335
+ refetchUser: authenticateUser,
336
+ setUser,
337
+ };
338
+ }
@@ -41,8 +41,8 @@ export declare function useAuthentication(partnerId: string): {
41
41
  name?: string | undefined;
42
42
  address?: string | undefined;
43
43
  email?: string | undefined;
44
- username?: string | undefined;
45
44
  phone?: string | undefined;
45
+ username?: string | undefined;
46
46
  fid?: string | undefined;
47
47
  };
48
48
  }[] | undefined;
@@ -63,6 +63,6 @@ export declare function useAuthentication(partnerId: string): {
63
63
  turnkeyOtpId?: string | undefined;
64
64
  };
65
65
  } | undefined;
66
- refetchUser: (wallet?: Wallet) => Promise<import("@feathersjs/authentication").AuthenticationResult>;
66
+ refetchUser: () => Promise<import("@feathersjs/authentication").AuthenticationResult>;
67
67
  setUser: (newUser?: import("@b3dotfun/b3-api").Users) => void;
68
68
  };
@@ -18,7 +18,7 @@ const in_app_1 = require("thirdweb/wallets/in-app");
18
18
  const wagmi_1 = require("wagmi");
19
19
  const LocalSDKProvider_1 = require("../components/B3Provider/LocalSDKProvider");
20
20
  const createWagmiConfig_1 = require("../utils/createWagmiConfig");
21
- const useTWAuth_1 = require("./useTWAuth");
21
+ const useAuth_1 = require("./useAuth");
22
22
  const useUserQuery_1 = require("./useUserQuery");
23
23
  const debug = (0, debug_1.debugB3React)("useAuthentication");
24
24
  function useAuthentication(partnerId) {
@@ -36,7 +36,7 @@ function useAuthentication(partnerId) {
36
36
  const setHasStartedConnecting = (0, react_1.useAuthStore)(state => state.setHasStartedConnecting);
37
37
  const setActiveWallet = (0, react_3.useSetActiveWallet)();
38
38
  const hasStartedConnecting = (0, react_1.useAuthStore)(state => state.hasStartedConnecting);
39
- const { authenticate } = (0, useTWAuth_1.useTWAuth)();
39
+ const { reAuthenticate } = (0, useAuth_1.useAuth)();
40
40
  const { user, setUser } = (0, useUserQuery_1.useUserQuery)();
41
41
  const useAutoConnectLoadingPrevious = (0, react_2.useRef)(false);
42
42
  const wagmiConfig = (0, createWagmiConfig_1.createWagmiConfig)({ partnerId });
@@ -96,18 +96,19 @@ function useAuthentication(partnerId) {
96
96
  (0, react_2.useEffect)(() => {
97
97
  syncWagmi();
98
98
  }, [wallets, syncWagmi]);
99
- const authenticateUser = (0, react_2.useCallback)(async (wallet) => {
99
+ /**
100
+ * Authenticate user using Turnkey
101
+ * Note: This no longer requires a wallet for authentication.
102
+ * Wallets are still used for signing transactions, but authentication is done via Turnkey email OTP.
103
+ *
104
+ * For backward compatibility, this function still accepts a wallet parameter,
105
+ * but it's not used for authentication anymore.
106
+ */
107
+ const authenticateUser = (0, react_2.useCallback)(async () => {
100
108
  setHasStartedConnecting(true);
101
- if (!wallet) {
102
- throw new Error("No wallet found during auto-connect");
103
- }
104
- const account = wallet ? wallet.getAccount() : activeWallet?.getAccount();
105
- if (!account) {
106
- throw new Error("No account found during auto-connect");
107
- }
108
109
  // Try to re-authenticate first
109
110
  try {
110
- const userAuth = await app_1.default.reAuthenticate();
111
+ const userAuth = await reAuthenticate();
111
112
  setUser(userAuth.user);
112
113
  setIsAuthenticated(true);
113
114
  setIsAuthenticating(false);
@@ -118,67 +119,50 @@ function useAuthentication(partnerId) {
118
119
  return userAuth;
119
120
  }
120
121
  catch (error) {
121
- // If re-authentication fails, try fresh authentication
122
- debug("Re-authentication failed, attempting fresh authentication");
123
- const userAuth = await authenticate(wallet, partnerId);
124
- setUser(userAuth.user);
125
- setIsAuthenticated(true);
122
+ // If re-authentication fails, user needs to authenticate via Turnkey
123
+ // This should be handled by the Turnkey auth modal/flow
124
+ debug("Re-authentication failed. User needs to authenticate via Turnkey.", error);
125
+ setIsAuthenticated(false);
126
126
  setIsAuthenticating(false);
127
- debug("Fresh authentication successful", { userAuth });
128
- // Authenticate on BSMNT with B3 JWT
129
- const b3Jwt = await (0, bsmnt_1.authenticateWithB3JWT)(userAuth.accessToken);
130
- debug("@@b3Jwt", b3Jwt);
131
- return userAuth;
132
- }
133
- }, [activeWallet, partnerId, authenticate, setIsAuthenticated, setIsAuthenticating, setUser, setHasStartedConnecting]);
134
- const logout = (0, react_2.useCallback)(async (callback) => {
135
- if (activeWallet) {
136
- debug("@@logout:activeWallet", activeWallet);
137
- disconnect(activeWallet);
138
- debug("@@logout:activeWallet", activeWallet);
127
+ throw new Error("Authentication required. Please authenticate via Turnkey.");
139
128
  }
140
- // Log out of each wallet
141
- wallets.forEach(wallet => {
142
- console.log("@@logging out", wallet);
143
- disconnect(wallet);
144
- });
145
- // Delete localStorage thirdweb:connected-wallet-ids
146
- // https://npc-labs.slack.com/archives/C070E6HNG85/p1750185115273099
147
- if (typeof localStorage !== "undefined") {
148
- localStorage.removeItem("thirdweb:connected-wallet-ids");
149
- localStorage.removeItem("wagmi.store");
150
- localStorage.removeItem("lastAuthProvider");
151
- localStorage.removeItem("b3-user");
152
- }
153
- app_1.default.logout();
154
- debug("@@logout:loggedOut");
155
- setIsAuthenticated(false);
156
- setIsConnected(false);
157
- setUser();
158
- callback?.();
159
- }, [activeWallet, disconnect, wallets, setIsAuthenticated, setUser, setIsConnected]);
129
+ }, [reAuthenticate, setIsAuthenticated, setIsAuthenticating, setUser, setHasStartedConnecting]);
130
+ /**
131
+ * Handle wallet connection
132
+ * Note: With Turnkey migration, wallet connection is primarily for signing transactions,
133
+ * not for authentication. Authentication should be done separately via Turnkey email OTP.
134
+ */
160
135
  const onConnect = (0, react_2.useCallback)(async (_walleAutoConnectedWith, allConnectedWallets) => {
161
136
  debug("@@useAuthentication:onConnect", { _walleAutoConnectedWith, allConnectedWallets });
137
+ const wallet = allConnectedWallets.find(wallet => wallet.id.startsWith("ecosystem."));
138
+ if (!wallet) {
139
+ throw new Error("No smart wallet found during auto-connect");
140
+ }
141
+ debug("@@useAuthentication:onConnect", { wallet });
162
142
  try {
163
- const wallet = allConnectedWallets.find(wallet => wallet.id.startsWith("ecosystem."));
164
- if (!wallet) {
165
- throw new Error("No smart wallet found during auto-connect");
166
- }
167
- debug("@@useAuthentication:onConnect", { wallet });
168
143
  setHasStartedConnecting(true);
169
144
  setIsConnected(true);
170
145
  setIsAuthenticating(true);
171
146
  await setActiveWallet(wallet);
172
- const userAuth = await authenticateUser(wallet);
173
- if (userAuth && onConnectCallback) {
174
- await onConnectCallback(wallet, userAuth.accessToken);
147
+ // Try to authenticate user (will use re-authenticate if session exists)
148
+ // If no session exists, authentication will need to happen via Turnkey flow
149
+ try {
150
+ const userAuth = await authenticateUser();
151
+ if (userAuth && onConnectCallback) {
152
+ await onConnectCallback(wallet, userAuth.accessToken);
153
+ }
154
+ }
155
+ catch (authError) {
156
+ // Authentication failed - this is expected if user hasn't authenticated via Turnkey yet
157
+ // The Turnkey auth modal should handle this
158
+ debug("@@useAuthentication:onConnect:authFailed", { authError });
159
+ // Don't set isAuthenticated to false here - let the Turnkey flow handle it
175
160
  }
176
161
  }
177
162
  catch (error) {
178
163
  debug("@@useAuthentication:onConnect:failed", { error });
179
164
  setIsAuthenticated(false);
180
165
  setUser(undefined);
181
- await logout();
182
166
  }
183
167
  finally {
184
168
  setIsAuthenticating(false);
@@ -189,19 +173,44 @@ function useAuthentication(partnerId) {
189
173
  isConnected,
190
174
  });
191
175
  }, [
176
+ onConnectCallback,
177
+ authenticateUser,
192
178
  isAuthenticated,
193
179
  isAuthenticating,
194
180
  isConnected,
195
- setHasStartedConnecting,
196
- setIsConnected,
197
- setIsAuthenticating,
198
181
  setActiveWallet,
199
- authenticateUser,
200
- onConnectCallback,
182
+ setHasStartedConnecting,
201
183
  setIsAuthenticated,
184
+ setIsAuthenticating,
185
+ setIsConnected,
202
186
  setUser,
203
- logout,
204
187
  ]);
188
+ const logout = (0, react_2.useCallback)(async (callback) => {
189
+ if (activeWallet) {
190
+ debug("@@logout:activeWallet", activeWallet);
191
+ disconnect(activeWallet);
192
+ debug("@@logout:activeWallet", activeWallet);
193
+ }
194
+ // Log out of each wallet
195
+ wallets.forEach(wallet => {
196
+ console.log("@@logging out", wallet);
197
+ disconnect(wallet);
198
+ });
199
+ // Delete localStorage thirdweb:connected-wallet-ids
200
+ // https://npc-labs.slack.com/archives/C070E6HNG85/p1750185115273099
201
+ if (typeof localStorage !== "undefined") {
202
+ localStorage.removeItem("thirdweb:connected-wallet-ids");
203
+ localStorage.removeItem("wagmi.store");
204
+ localStorage.removeItem("lastAuthProvider");
205
+ localStorage.removeItem("b3-user");
206
+ }
207
+ app_1.default.logout();
208
+ debug("@@logout:loggedOut");
209
+ setIsAuthenticated(false);
210
+ setIsConnected(false);
211
+ setUser();
212
+ callback?.();
213
+ }, [activeWallet, disconnect, wallets, setIsAuthenticated, setUser, setIsConnected]);
205
214
  const { isLoading: useAutoConnectLoading } = (0, react_3.useAutoConnect)({
206
215
  client: thirdweb_1.client,
207
216
  wallets: [wallet],
@@ -1,4 +1,7 @@
1
1
  import { Wallet } from "thirdweb/wallets";
2
+ /**
3
+ * @deprecated Use useAuth() with Turnkey authentication instead
4
+ */
2
5
  export declare function useTWAuth(): {
3
6
  authenticate: (wallet: Wallet, partnerId: string) => Promise<import("@feathersjs/authentication").AuthenticationResult>;
4
7
  };
@@ -4,11 +4,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.useTWAuth = useTWAuth;
7
+ /**
8
+ * @deprecated This hook is deprecated. Use useAuth() with Turnkey authentication instead.
9
+ * This file is kept for backward compatibility but should not be used in new code.
10
+ */
7
11
  const app_1 = __importDefault(require("../../../global-account/app"));
8
12
  const debug_1 = __importDefault(require("../../../shared/utils/debug"));
9
13
  const react_1 = require("react");
10
14
  const useSearchParamsSSR_1 = require("./useSearchParamsSSR");
15
+ /**
16
+ * @deprecated Use useAuth() with Turnkey authentication instead
17
+ */
11
18
  function useTWAuth() {
19
+ console.warn("useTWAuth is deprecated. Please migrate to useAuth() with Turnkey authentication. See useTurnkeyAuth.ts for the new implementation.");
12
20
  const referralCode = (0, useSearchParamsSSR_1.useSearchParam)("referralCode");
13
21
  const authenticate = (0, react_1.useCallback)(async (wallet, partnerId) => {
14
22
  if (!wallet || !wallet?.getAuthToken?.())