@b3dotfun/sdk 0.0.82 → 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.
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +57 -12
- package/dist/cjs/global-account/react/hooks/index.d.ts +1 -0
- package/dist/cjs/global-account/react/hooks/index.js +3 -1
- package/dist/cjs/global-account/react/hooks/useAuth.d.ts +76 -0
- package/dist/cjs/global-account/react/hooks/useAuth.js +338 -0
- package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +1 -1
- package/dist/cjs/global-account/react/hooks/useAuthentication.js +36 -25
- package/dist/cjs/global-account/react/hooks/useTWAuth.d.ts +3 -0
- package/dist/cjs/global-account/react/hooks/useTWAuth.js +8 -0
- package/dist/cjs/global-account/react/hooks/useTurnkeyAuth.js +54 -24
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +57 -12
- package/dist/esm/global-account/react/hooks/index.d.ts +1 -0
- package/dist/esm/global-account/react/hooks/index.js +1 -0
- package/dist/esm/global-account/react/hooks/useAuth.d.ts +76 -0
- package/dist/esm/global-account/react/hooks/useAuth.js +332 -0
- package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +1 -1
- package/dist/esm/global-account/react/hooks/useAuthentication.js +36 -25
- package/dist/esm/global-account/react/hooks/useTWAuth.d.ts +3 -0
- package/dist/esm/global-account/react/hooks/useTWAuth.js +8 -0
- package/dist/esm/global-account/react/hooks/useTurnkeyAuth.js +54 -24
- package/dist/types/global-account/react/hooks/index.d.ts +1 -0
- package/dist/types/global-account/react/hooks/useAuth.d.ts +76 -0
- package/dist/types/global-account/react/hooks/useAuthentication.d.ts +1 -1
- package/dist/types/global-account/react/hooks/useTWAuth.d.ts +3 -0
- package/package.json +1 -1
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +77 -22
- package/src/global-account/react/hooks/index.ts +1 -0
- package/src/global-account/react/hooks/useAuth.ts +380 -0
- package/src/global-account/react/hooks/useAuthentication.ts +51 -47
- package/src/global-account/react/hooks/useTWAuth.tsx +10 -0
- package/src/global-account/react/hooks/useTurnkeyAuth.ts +59 -26
|
@@ -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
|
|
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 {
|
|
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
|
-
|
|
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
|
|
111
|
+
const userAuth = await reAuthenticate();
|
|
111
112
|
setUser(userAuth.user);
|
|
112
113
|
setIsAuthenticated(true);
|
|
113
114
|
setIsAuthenticating(false);
|
|
@@ -118,19 +119,19 @@ function useAuthentication(partnerId) {
|
|
|
118
119
|
return userAuth;
|
|
119
120
|
}
|
|
120
121
|
catch (error) {
|
|
121
|
-
// If re-authentication fails,
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
|
|
128
|
-
// Authenticate on BSMNT with B3 JWT
|
|
129
|
-
const b3Jwt = await (0, bsmnt_1.authenticateWithB3JWT)(userAuth.accessToken);
|
|
130
|
-
debug("@@b3Jwt", b3Jwt);
|
|
131
|
-
return userAuth;
|
|
127
|
+
throw new Error("Authentication required. Please authenticate via Turnkey.");
|
|
132
128
|
}
|
|
133
|
-
}, [
|
|
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
|
+
*/
|
|
134
135
|
const onConnect = (0, react_2.useCallback)(async (_walleAutoConnectedWith, allConnectedWallets) => {
|
|
135
136
|
debug("@@useAuthentication:onConnect", { _walleAutoConnectedWith, allConnectedWallets });
|
|
136
137
|
const wallet = allConnectedWallets.find(wallet => wallet.id.startsWith("ecosystem."));
|
|
@@ -143,9 +144,19 @@ function useAuthentication(partnerId) {
|
|
|
143
144
|
setIsConnected(true);
|
|
144
145
|
setIsAuthenticating(true);
|
|
145
146
|
await setActiveWallet(wallet);
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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
|
|
149
160
|
}
|
|
150
161
|
}
|
|
151
162
|
catch (error) {
|
|
@@ -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?.())
|
|
@@ -4,11 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.useTurnkeyAuth = useTurnkeyAuth;
|
|
7
|
-
const
|
|
8
|
-
const stores_1 = require("../stores");
|
|
7
|
+
const debug_1 = require("../../../shared/utils/debug");
|
|
9
8
|
const react_1 = require("react");
|
|
9
|
+
const app_1 = __importDefault(require("../../app"));
|
|
10
10
|
const useB3_1 = require("../components/B3Provider/useB3");
|
|
11
|
-
const
|
|
11
|
+
const stores_1 = require("../stores");
|
|
12
|
+
const useAuth_1 = require("./useAuth");
|
|
12
13
|
const debug = (0, debug_1.debugB3React)("useTurnkeyAuth");
|
|
13
14
|
/**
|
|
14
15
|
* Hook for Turnkey email-based OTP authentication
|
|
@@ -23,29 +24,55 @@ function useTurnkeyAuth() {
|
|
|
23
24
|
const [error, setError] = (0, react_1.useState)(null);
|
|
24
25
|
const setIsAuthenticating = (0, stores_1.useAuthStore)(state => state.setIsAuthenticating);
|
|
25
26
|
const setIsAuthenticated = (0, stores_1.useAuthStore)(state => state.setIsAuthenticated);
|
|
26
|
-
const {
|
|
27
|
+
const { partnerId } = (0, useB3_1.useB3)();
|
|
28
|
+
const { authenticate } = (0, useAuth_1.useAuth)();
|
|
27
29
|
/**
|
|
28
30
|
* Step 1: Initiate login with email
|
|
29
|
-
* - Calls backend to create sub-org (if needed) and send OTP
|
|
31
|
+
* - Calls backend turnkey-jwt strategy (init action) to create sub-org (if needed) and send OTP
|
|
30
32
|
* - Returns otpId to use in verification step
|
|
33
|
+
*
|
|
34
|
+
* Note: Uses the turnkey-jwt authentication strategy, not the service directly.
|
|
35
|
+
* The turnkey-jwt strategy handles both OTP flow (init/verify) and final authentication.
|
|
31
36
|
*/
|
|
32
37
|
const initiateLogin = (0, react_1.useCallback)(async (email) => {
|
|
33
38
|
setIsLoading(true);
|
|
34
39
|
setError(null);
|
|
35
40
|
setIsAuthenticating(true);
|
|
36
41
|
try {
|
|
37
|
-
if (!user?.userId) {
|
|
38
|
-
throw new Error("User ID is required to initiate Turnkey login.");
|
|
39
|
-
}
|
|
40
42
|
debug(`Initiating login for: ${email}`);
|
|
41
|
-
//
|
|
42
|
-
|
|
43
|
+
// Use authentication service with turnkey-jwt strategy (init action)
|
|
44
|
+
// userId is resolved from authentication context on the backend (params.user.userId)
|
|
45
|
+
// Backend will get userId from _params.user?.userId if authenticated, or handle unauthenticated case
|
|
46
|
+
// So we only need to send email
|
|
47
|
+
debug(`Calling app.authenticate with turnkey-jwt strategy (init action)`, { email });
|
|
48
|
+
const response = await app_1.default.authenticate({
|
|
49
|
+
strategy: "turnkey-jwt",
|
|
50
|
+
action: "init",
|
|
51
|
+
email,
|
|
52
|
+
});
|
|
53
|
+
// The strategy returns the TurnkeyAuthInitResponse directly
|
|
54
|
+
const data = response;
|
|
43
55
|
debug(`OTP initialized successfully. OtpId: ${data.otpId}`);
|
|
44
56
|
return data;
|
|
45
57
|
}
|
|
46
58
|
catch (err) {
|
|
47
59
|
debug("Error initiating login:", err);
|
|
48
|
-
|
|
60
|
+
// Provide more detailed error information
|
|
61
|
+
let errorMessage = "Failed to send OTP email. Please try again.";
|
|
62
|
+
if (err.message) {
|
|
63
|
+
errorMessage = err.message;
|
|
64
|
+
}
|
|
65
|
+
else if (err.name === "TypeError" && err.message?.includes("fetch")) {
|
|
66
|
+
errorMessage = "Network error: Unable to reach the server. Please check your connection and try again.";
|
|
67
|
+
}
|
|
68
|
+
else if (err.code === "ECONNREFUSED" || err.code === "ENOTFOUND") {
|
|
69
|
+
errorMessage = "Connection error: Unable to reach the server. Please check your internet connection.";
|
|
70
|
+
}
|
|
71
|
+
else if (err.response) {
|
|
72
|
+
// FeathersJS error response
|
|
73
|
+
errorMessage = err.response.message || err.message || errorMessage;
|
|
74
|
+
debug("FeathersJS error response:", err.response);
|
|
75
|
+
}
|
|
49
76
|
setError(errorMessage);
|
|
50
77
|
throw err;
|
|
51
78
|
}
|
|
@@ -53,11 +80,11 @@ function useTurnkeyAuth() {
|
|
|
53
80
|
setIsLoading(false);
|
|
54
81
|
setIsAuthenticating(false);
|
|
55
82
|
}
|
|
56
|
-
}, [
|
|
83
|
+
}, [setIsAuthenticating]);
|
|
57
84
|
/**
|
|
58
85
|
* Step 2: Verify OTP and authenticate
|
|
59
|
-
* - Verifies OTP with backend
|
|
60
|
-
* - Gets Turnkey session JWT
|
|
86
|
+
* - Verifies OTP with backend via turnkey-jwt strategy (verify action)
|
|
87
|
+
* - Gets Turnkey session JWT from the verify response
|
|
61
88
|
* - Authenticates with b3-api using "turnkey-jwt" strategy
|
|
62
89
|
* - JWT automatically stored in cookies by SDK
|
|
63
90
|
*/
|
|
@@ -66,19 +93,22 @@ function useTurnkeyAuth() {
|
|
|
66
93
|
setError(null);
|
|
67
94
|
setIsAuthenticating(true);
|
|
68
95
|
try {
|
|
69
|
-
debug(`Verifying OTP...`, {
|
|
70
|
-
// Step 1: Verify OTP
|
|
71
|
-
|
|
96
|
+
debug(`Verifying OTP...`, { otpId });
|
|
97
|
+
// Step 1: Verify OTP with backend using turnkey-jwt strategy (verify action)
|
|
98
|
+
// This returns the Turnkey session JWT
|
|
99
|
+
const response = await app_1.default.authenticate({
|
|
100
|
+
strategy: "turnkey-jwt",
|
|
101
|
+
action: "verify",
|
|
72
102
|
otpId,
|
|
73
103
|
otpCode,
|
|
74
104
|
});
|
|
75
|
-
|
|
105
|
+
// The strategy returns the TurnkeyAuthVerifyResponse directly
|
|
106
|
+
const verifyResult = response;
|
|
107
|
+
const { turnkeySessionJwt } = verifyResult;
|
|
108
|
+
debug(`OTP verified! Got Turnkey session JWT. Authenticating with b3-api...`);
|
|
76
109
|
// Step 2: Authenticate with b3-api using Turnkey JWT
|
|
77
|
-
//
|
|
78
|
-
const authResult = await
|
|
79
|
-
strategy: "turnkey-jwt",
|
|
80
|
-
accessToken: turnkeySessionJwt,
|
|
81
|
-
});
|
|
110
|
+
// Use the unified useAuth hook for authentication with "turnkey-jwt" strategy
|
|
111
|
+
const authResult = await authenticate(turnkeySessionJwt, partnerId || "");
|
|
82
112
|
debug(`Successfully authenticated with b3-api!`, authResult);
|
|
83
113
|
// Update auth store to reflect authenticated state
|
|
84
114
|
setIsAuthenticated(true);
|
|
@@ -98,7 +128,7 @@ function useTurnkeyAuth() {
|
|
|
98
128
|
setIsLoading(false);
|
|
99
129
|
setIsAuthenticating(false);
|
|
100
130
|
}
|
|
101
|
-
}, [
|
|
131
|
+
}, [partnerId, setIsAuthenticating, setIsAuthenticated, authenticate]);
|
|
102
132
|
const clearError = (0, react_1.useCallback)(() => {
|
|
103
133
|
setError(null);
|
|
104
134
|
}, []);
|
|
@@ -3,6 +3,7 @@ import { Loading, useAuthStore, useB3, useGetAllTWSigners, useModalStore, } from
|
|
|
3
3
|
import { debugB3React } from "../../../../shared/utils/debug.js";
|
|
4
4
|
import { useCallback, useEffect, useState } from "react";
|
|
5
5
|
import { useActiveAccount } from "thirdweb/react";
|
|
6
|
+
import { TurnkeyAuthModal } from "../TurnkeyAuthModal.js";
|
|
6
7
|
import { SignInWithB3Privy } from "./SignInWithB3Privy.js";
|
|
7
8
|
import { LoginStep, LoginStepContainer } from "./steps/LoginStep.js";
|
|
8
9
|
import { LoginStepCustom } from "./steps/LoginStepCustom.js";
|
|
@@ -20,7 +21,9 @@ export function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySucce
|
|
|
20
21
|
const account = useActiveAccount();
|
|
21
22
|
const isAuthenticating = useAuthStore(state => state.isAuthenticating);
|
|
22
23
|
const isAuthenticated = useAuthStore(state => state.isAuthenticated);
|
|
24
|
+
const setIsAuthenticated = useAuthStore(state => state.setIsAuthenticated);
|
|
23
25
|
const isConnected = useAuthStore(state => state.isConnected);
|
|
26
|
+
const setIsConnected = useAuthStore(state => state.setIsConnected);
|
|
24
27
|
const setJustCompletedLogin = useAuthStore(state => state.setJustCompletedLogin);
|
|
25
28
|
const [refetchCount, setRefetchCount] = useState(0);
|
|
26
29
|
const [refetchError, setRefetchError] = useState(null);
|
|
@@ -122,6 +125,10 @@ export function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySucce
|
|
|
122
125
|
debug("Refetching user after Turnkey success...");
|
|
123
126
|
await refetchUser();
|
|
124
127
|
debug("User refetched successfully");
|
|
128
|
+
// Set authentication and connection state so UI updates properly
|
|
129
|
+
setIsAuthenticated(true);
|
|
130
|
+
setIsConnected(true);
|
|
131
|
+
setJustCompletedLogin(true);
|
|
125
132
|
// After user data is refreshed, close Turnkey modal and go back to sign-in flow
|
|
126
133
|
debug("Switching back to signInWithB3 modal");
|
|
127
134
|
setB3ModalContentType({
|
|
@@ -151,6 +158,9 @@ export function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySucce
|
|
|
151
158
|
closeAfterLogin,
|
|
152
159
|
source,
|
|
153
160
|
signersEnabled,
|
|
161
|
+
setIsAuthenticated,
|
|
162
|
+
setIsConnected,
|
|
163
|
+
setJustCompletedLogin,
|
|
154
164
|
]);
|
|
155
165
|
// Handle post-login flow after signers are loaded
|
|
156
166
|
useEffect(() => {
|
|
@@ -286,21 +296,56 @@ export function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySucce
|
|
|
286
296
|
if (refetchError) {
|
|
287
297
|
content = (_jsx(LoginStepContainer, { partnerId: partnerId, children: _jsx("div", { className: "p-4 text-center text-red-500", children: refetchError }) }));
|
|
288
298
|
}
|
|
289
|
-
else if (isAuthenticating || (isFetchingSigners && step === "login") || source === "requestPermissions") {
|
|
290
|
-
content = (_jsx(LoginStepContainer, { partnerId: partnerId, children: _jsx("div", { className: "my-8 flex min-h-[350px] items-center justify-center", children: _jsx(Loading, { variant: "white", size: "lg" }) }) }));
|
|
291
|
-
}
|
|
292
299
|
else if (step === "login") {
|
|
293
|
-
//
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
//
|
|
299
|
-
|
|
300
|
+
// PRIORITY: If Turnkey is enabled, show Turnkey modal FIRST as the primary authentication option
|
|
301
|
+
// Show Turnkey when enabled and not already completed in this session
|
|
302
|
+
const shouldShowTurnkeyFirst = enableTurnkey && !turnkeyAuthCompleted;
|
|
303
|
+
if (shouldShowTurnkeyFirst) {
|
|
304
|
+
// Don't show loading spinner for Turnkey - let the modal handle its own loading state
|
|
305
|
+
// This prevents the infinite loop where isAuthenticating causes the modal to be replaced
|
|
306
|
+
debug("Showing Turnkey as primary authentication option", {
|
|
307
|
+
enableTurnkey,
|
|
308
|
+
turnkeyAuthCompleted,
|
|
309
|
+
isAuthenticated,
|
|
310
|
+
});
|
|
311
|
+
// Show Turnkey authentication as primary option
|
|
312
|
+
content = (_jsx(LoginStepContainer, { partnerId: partnerId, children: _jsx(TurnkeyAuthModal, { onSuccess: async (authenticatedUser) => {
|
|
313
|
+
debug("Turnkey authentication successful in primary flow", { authenticatedUser });
|
|
314
|
+
setTurnkeyAuthCompleted(true);
|
|
315
|
+
// After Turnkey auth, refetch user to get the full user object
|
|
316
|
+
await refetchUser();
|
|
317
|
+
// User is now authenticated via Turnkey
|
|
318
|
+
// Set both isAuthenticated and isConnected to true so UI updates properly
|
|
319
|
+
// Wallet connection is optional and can happen later for signing transactions
|
|
320
|
+
setIsAuthenticated(true);
|
|
321
|
+
setIsConnected(true);
|
|
322
|
+
setJustCompletedLogin(true);
|
|
323
|
+
// Call the login success callback
|
|
324
|
+
onLoginSuccess?.({});
|
|
325
|
+
}, onClose: () => {
|
|
326
|
+
// If user closes Turnkey modal, they can still use wallet connection as fallback
|
|
327
|
+
setTurnkeyAuthCompleted(true);
|
|
328
|
+
}, initialEmail: "", skipToOtp: false }) }));
|
|
300
329
|
}
|
|
301
330
|
else {
|
|
302
|
-
//
|
|
303
|
-
|
|
331
|
+
// Show loading spinner only if not in Turnkey flow
|
|
332
|
+
if (isAuthenticating || (isFetchingSigners && step === "login") || source === "requestPermissions") {
|
|
333
|
+
content = (_jsx(LoginStepContainer, { partnerId: partnerId, children: _jsx("div", { className: "my-8 flex min-h-[350px] items-center justify-center", children: _jsx(Loading, { variant: "white", size: "lg" }) }) }));
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
// Custom strategy
|
|
337
|
+
if (strategies?.[0] === "privy") {
|
|
338
|
+
content = _jsx(SignInWithB3Privy, { onSuccess: handleLoginSuccess, chain: chain });
|
|
339
|
+
}
|
|
340
|
+
else if (strategies) {
|
|
341
|
+
// Strategies are explicitly provided
|
|
342
|
+
content = (_jsx(LoginStepCustom, { strategies: strategies, chain: chain, onSuccess: handleLoginSuccess, onError: onError, automaticallySetFirstEoa: !!automaticallySetFirstEoa }));
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
// Default to handle all strategies we support
|
|
346
|
+
content = _jsx(LoginStep, { chain: chain, onSuccess: handleLoginSuccess, onError: onError });
|
|
347
|
+
}
|
|
348
|
+
}
|
|
304
349
|
}
|
|
305
350
|
}
|
|
306
351
|
return content;
|
|
@@ -3,6 +3,7 @@ export { useAccountAssets } from "./useAccountAssets";
|
|
|
3
3
|
export { useAccountWallet } from "./useAccountWallet";
|
|
4
4
|
export { useAddTWSessionKey } from "./useAddTWSessionKey";
|
|
5
5
|
export { useAnalytics } from "./useAnalytics";
|
|
6
|
+
export { useAuth } from "./useAuth";
|
|
6
7
|
export { useAuthentication } from "./useAuthentication";
|
|
7
8
|
export { useB3BalanceFromAddresses } from "./useB3BalanceFromAddresses";
|
|
8
9
|
export { useB3EnsName } from "./useB3EnsName";
|
|
@@ -3,6 +3,7 @@ export { useAccountAssets } from "./useAccountAssets.js";
|
|
|
3
3
|
export { useAccountWallet } from "./useAccountWallet.js";
|
|
4
4
|
export { useAddTWSessionKey } from "./useAddTWSessionKey.js";
|
|
5
5
|
export { useAnalytics } from "./useAnalytics.js";
|
|
6
|
+
export { useAuth } from "./useAuth.js";
|
|
6
7
|
export { useAuthentication } from "./useAuthentication.js";
|
|
7
8
|
export { useB3BalanceFromAddresses } from "./useB3BalanceFromAddresses.js";
|
|
8
9
|
export { useB3EnsName } from "./useB3EnsName.js";
|
|
@@ -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
|
+
};
|